manage_dotfiles.sh 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. #!/bin/bash
  2. # BASH_SOURCE means the directory location of this bash script
  3. DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )"
  4. exclude=("scripts" "README.md")
  5. configs=("conky" "openbox" "tint2")
  6. prompt() {
  7. while true; do
  8. if [ "${2:-}" = "Y" ]; then
  9. options="Y/n"
  10. default=Y
  11. elif [ "${2:-}" = "N" ]; then
  12. options="y/N"
  13. default=N
  14. else
  15. options="y/n"
  16. default=
  17. fi
  18. read -p "$1 [$options] " -n 1 -r REPLY
  19. echo ""
  20. if [ -z "$REPLY" ]; then
  21. REPLY=$default
  22. fi
  23. case "$REPLY" in
  24. Y*|y*) return 0 ;;
  25. N*|n*) return 1 ;;
  26. esac
  27. done
  28. }
  29. link() {
  30. if [ -e "$1/.$2" ]; then
  31. if prompt "$1/.$2 exists! Delete?" N; then
  32. # It might be a very, very bad idea to rm -rf.
  33. rm -rf "$1/.$2"
  34. ln -sn "$DIR/$2" "$1/.$2"
  35. fi
  36. echo "" # Intentional extra echo
  37. else
  38. ln -sn "$DIR/$2" "$1/.$2"
  39. fi
  40. }
  41. install_dotfiles() {
  42. mkdir -p $HOME/.config/{,xfce4/xfconf/xfce-perchannel-xml/xfce4-notifyd.xml/}
  43. confs=(
  44. 'bashrc'
  45. 'fehbg'
  46. 'gitconfig'
  47. 'gtkrc-2.0'
  48. 'vim'
  49. 'vimrc'
  50. 'xinitrc'
  51. 'zshrc'
  52. 'Xmodmap'
  53. 'Xresources'
  54. 'xbindkeysrc'
  55. 'config/conky'
  56. 'config/openbox'
  57. 'config/tint2'
  58. 'config/touchegg'
  59. 'config/awesome'
  60. 'config/xfce4/xfconf/xfce-perchannel-xml/xfce4-notifyd.xml'
  61. )
  62. for conf in ${confs[@]}; do
  63. echo "Linking $conf to $HOME/.$conf"
  64. link "$HOME" "$conf"
  65. done
  66. # Finish up linking and directory stuff
  67. ln -fsn "$DIR"/vim/pathogen/autoload "$DIR"/vim/
  68. mkdir -p "$DIR"/vim/tmp/{backup,swap,undo}
  69. if prompt "Install airline glyphs?" N; then
  70. yaourt -S powerline-fonts-git
  71. fi
  72. mkdir -p "$DIR"/vim/tmp/{backup,swap,undo,view}
  73. }
  74. update_git_submodules() {
  75. git submodule update --init --recursive
  76. git submodule foreach --recursive git pull origin master
  77. }
  78. compile_ycm() {
  79. echo "Compiling YouCompleteMe"
  80. if prompt "Install boost (required for YCM)?" N; then
  81. yaourt -S boost
  82. fi
  83. cd "$DIR"/vim/bundle/YouCompleteMe
  84. ./install.sh
  85. cd "$DIR"
  86. }
  87. compile_exctags() {
  88. git clone git://github.com/jakedouglas/exuberant-ctags.git "$DIR"/exuberant-ctags
  89. cd "$DIR"/exuberant-ctags
  90. ./configure
  91. make
  92. sudo make install
  93. rm -rf "$DIR"/exuberant-ctags
  94. }
  95. case "$1" in
  96. -a|--all)
  97. install_dotfiles
  98. update_git_submodules
  99. compile_ycm
  100. compile_exctags
  101. ;;
  102. -i|--install_dotfiles)
  103. install_dotfiles
  104. ;;
  105. -g|--update_git_submodules)
  106. update_git_submodules
  107. ;;
  108. -y|--compile_ycm)
  109. compile_ycm
  110. ;;
  111. -e|--compile_exctags)
  112. compile_exctags
  113. ;;
  114. *)
  115. echo "Usage: manage_dotfiles <option>"
  116. echo "Options:"
  117. echo " -i --install_dotfiles Install dotfiles to home directory"
  118. echo " -g --update_git_submodules Update git submodules"
  119. echo " -y --compile_ycm Compile YouCompleteMe"
  120. echo " -e --compile_exctags Compile Exuberant-ctags"
  121. echo " -a --all All of the above"
  122. ;;
  123. esac