manage_dotfiles.sh 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. confs=(
  43. 'tmux.conf'
  44. 'bashrc'
  45. 'gitconfig'
  46. 'vim'
  47. 'vimrc'
  48. 'zshrc'
  49. )
  50. for conf in ${confs[@]}; do
  51. echo "Linking $conf to $HOME/.$conf"
  52. link "$HOME" "$conf"
  53. done
  54. # Finish up linking and directory stuff
  55. ln -fsn "$DIR"/vim/pathogen/autoload "$DIR"/vim/
  56. mkdir -p "$DIR"/vim/tmp/{backup,swap,undo,view}
  57. }
  58. update_git_submodules() {
  59. git submodule foreach --recursive git reset --hard origin/master
  60. git submodule foreach --recursive git pull origin master
  61. git submodule foreach git submodule update --init --recursive
  62. }
  63. compile_ycm() {
  64. echo "Compiling YouCompleteMe"
  65. cd "$DIR"/vim/bundle/YouCompleteMe
  66. python2 ./install.py
  67. cd "$DIR"
  68. }
  69. compile_exctags() {
  70. git clone git://github.com/jakedouglas/exuberant-ctags.git "$DIR"/exuberant-ctags
  71. cd "$DIR"/exuberant-ctags
  72. ./configure
  73. make
  74. sudo make install
  75. rm -rf "$DIR"/exuberant-ctags
  76. }
  77. case "$1" in
  78. -a|--all)
  79. install_dotfiles
  80. update_git_submodules
  81. compile_ycm
  82. compile_exctags
  83. ;;
  84. -i|--install_dotfiles)
  85. install_dotfiles
  86. ;;
  87. -g|--update_git_submodules)
  88. update_git_submodules
  89. ;;
  90. -y|--compile_ycm)
  91. compile_ycm
  92. ;;
  93. -e|--compile_exctags)
  94. compile_exctags
  95. ;;
  96. *)
  97. echo "Usage: manage_dotfiles <option>"
  98. echo "Options:"
  99. echo " -i --install_dotfiles Install dotfiles to home directory"
  100. echo " -g --update_git_submodules Update git submodules"
  101. echo " -y --compile_ycm Compile YouCompleteMe"
  102. echo " -e --compile_exctags Compile Exuberant-ctags"
  103. echo " -a --all All of the above"
  104. ;;
  105. esac