manage_dotfiles.sh 3.0 KB

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