manage_dotfiles.sh 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. }
  69. update_git_submodules() {
  70. git submodule update --init --recursive
  71. git submodule foreach --recursive git pull origin master
  72. }
  73. compile_ycm() {
  74. echo "Compiling YouCompleteMe"
  75. if prompt "Install boost (required for YCM)?" N; then
  76. yaourt -S boost
  77. fi
  78. cd "$DIR"/vim/bundle/YouCompleteMe
  79. ./install.sh
  80. }
  81. compile_exctags() {
  82. git clone git://github.com/jakedouglas/exuberant-ctags.git "$DIR"/exuberant-ctags
  83. cd "$DIR"/exuberant-ctags
  84. ./configure
  85. make
  86. sudo make install
  87. rm -rf "$DIR"/exuberant-ctags
  88. }
  89. case "$1" in
  90. -a|--all)
  91. install_dotfiles
  92. update_git_submodules
  93. compile_ycm
  94. compile_exctags
  95. ;;
  96. -i|--install_dotfiles)
  97. install_dotfiles
  98. ;;
  99. -g|--update_git_submodules)
  100. update_git_submodules
  101. ;;
  102. -y|--compile_ycm)
  103. compile_ycm
  104. ;;
  105. -e|--compile_exctags)
  106. compile_exctags
  107. ;;
  108. *)
  109. echo "Usage: install_dotfiles <option>"
  110. echo "Options:"
  111. echo " -i --install_dotfiles Install dotfiles to home directory"
  112. echo " -g --update_git_submodules Update git submodules"
  113. echo " -y --compile_ycm Compile YouCompleteMe"
  114. echo " -e --compile_exctags Compile Exuberant-ctags"
  115. echo " -a --all All of the above"
  116. ;;
  117. esac