manage_dotfiles.sh 2.9 KB

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