install_dotfiles.sh 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. for i in $(ls "$DIR"); do
  48. # Ignore some files
  49. elem_in "$i" "${exclude[@]}"
  50. if [[ $? == 1 ]]; then continue; fi
  51. # Differentiate between dotfiles and .config/* files
  52. elem_in "$i" "${configs[@]}"
  53. if [[ $? == 1 ]]; then
  54. echo "Linking $i to $HOME/.config/$i"
  55. link "$HOME/.config" "$i"
  56. else
  57. echo "Linking $i to $HOME/.$i"
  58. link "$HOME" "$i" "."
  59. fi
  60. done
  61. # Finish up linking and directory stuff
  62. ln -fsn "$DIR"/vim/pathogen/autoload "$DIR"/vim/
  63. mkdir -p "$DIR"/vim/tmp/{backup,swap,undo}
  64. if prompt "Install airline glyphs?" N; then
  65. yaourt -S powerline-fonts-git
  66. fi
  67. if prompt "Update git submodules?" N ; then
  68. git submodule update --init --recursive
  69. git submodule foreach --recursive git pull origin master
  70. fi
  71. if prompt "Auto compile YouCompleteMe?" N; then
  72. if prompt "Install boost?" N; then
  73. yaourt -S boost
  74. fi
  75. echo "Compiling YouCompleteMe"
  76. cd "$DIR"/vim/bundle/YouCompleteMe
  77. ./install.sh
  78. fi
  79. if prompt "Auto compile exuberant-ctags?" N; then
  80. echo ""
  81. git clone git://github.com/jakedouglas/exuberant-ctags.git "$DIR"/exuberant-ctags
  82. cd "$DIR"/exuberant-ctags
  83. ./configure
  84. make
  85. sudo make install
  86. rm -rf "$DIR"/exuberant-ctags
  87. fi