manage_dotfiles.sh 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. 'tmux.conf'
  45. 'bashrc'
  46. 'fehbg'
  47. 'gitconfig'
  48. 'gitignore'
  49. 'git_template'
  50. 'gtkrc-2.0'
  51. 'vim'
  52. 'vimrc'
  53. 'xinitrc'
  54. 'zshrc'
  55. 'Xmodmap'
  56. 'Xresources'
  57. 'xbindkeysrc'
  58. 'conkyinit'
  59. 'config/conky'
  60. 'config/openbox'
  61. 'config/tint2'
  62. 'config/touchegg'
  63. 'config/awesome'
  64. 'config/xfce4/xfconf/xfce-perchannel-xml/xfce4-notifyd.xml'
  65. )
  66. for conf in ${confs[@]}; do
  67. echo "Linking $conf to $HOME/.$conf"
  68. link "$HOME" "$conf"
  69. done
  70. # For neovim
  71. ln -sn $DIR/vim $HOME/.config/nvim
  72. ln -sn $DIR/vimrc $HOME/.config/nvim/init.vim
  73. # Finish up linking and directory stuff
  74. ln -fsn "$DIR"/vim/pathogen/autoload "$DIR"/vim/
  75. mkdir -p "$DIR"/vim/tmp/{backup,swap,undo}
  76. if prompt "Install airline glyphs?" N; then
  77. yaourt -S powerline-fonts-git
  78. fi
  79. mkdir -p "$DIR"/vim/tmp/{backup,swap,undo,view}
  80. }
  81. update_git_submodules() {
  82. git submodule foreach --recursive git reset --hard origin/master
  83. git submodule foreach --recursive git pull origin master
  84. git submodule foreach git submodule update --init --recursive
  85. }
  86. compile_ycm() {
  87. echo "Compiling YouCompleteMe"
  88. if prompt "Install boost (required for YCM)?" N; then
  89. yaourt -S boost
  90. fi
  91. cd "$DIR"/vim/bundle/YouCompleteMe
  92. python2 ./install.py --racer-completer
  93. cd "$DIR"
  94. }
  95. compile_exctags() {
  96. yaourt -S universal-ctags-git
  97. }
  98. case "$1" in
  99. -a|--all)
  100. install_dotfiles
  101. update_git_submodules
  102. compile_ycm
  103. compile_exctags
  104. ;;
  105. -i|--install_dotfiles)
  106. install_dotfiles
  107. ;;
  108. -g|--update_git_submodules)
  109. update_git_submodules
  110. ;;
  111. -y|--compile_ycm)
  112. compile_ycm
  113. ;;
  114. -e|--compile_exctags)
  115. compile_exctags
  116. ;;
  117. *)
  118. echo "Usage: manage_dotfiles <option>"
  119. echo "Options:"
  120. echo " -i --install_dotfiles Install dotfiles to home directory"
  121. echo " -g --update_git_submodules Update git submodules"
  122. echo " -y --compile_ycm Compile YouCompleteMe"
  123. echo " -e --compile_exctags Compile Exuberant-ctags"
  124. echo " -a --all All of the above"
  125. ;;
  126. esac