manage_dotfiles.sh 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. 'ackrc'
  44. 'ag-ignore'
  45. 'bashrc'
  46. 'git_template'
  47. 'gitconfig'
  48. 'gitignore'
  49. 'tmux.conf'
  50. 'vim'
  51. 'vimrc'
  52. 'zshrc'
  53. )
  54. for conf in ${confs[@]}; do
  55. echo "Linking $conf to $HOME/.$conf"
  56. link "$HOME" "$conf"
  57. done
  58. ln -fsn "$PWD/vim" "$HOME/.config/nvim"
  59. ln -fsn "$PWD/vimrc" "$HOME/.config/init.vim"
  60. # Finish up linking and directory stuff
  61. ln -fsn "$DIR"/vim/pathogen/autoload "$DIR"/vim/
  62. mkdir -p "$DIR"/vim/tmp/{backup,swap,undo,view}
  63. }
  64. update_git_submodules() {
  65. git submodule update --init --recursive
  66. # vim/bundle/YouCompleteMe/third_party/ycmd/third_party/mrab-regex doesn't
  67. # have a main/master branch, so include "hg"
  68. #
  69. # git fetch -a && \
  70. # git checkout -b rm_detached_head && \
  71. # (git checkout master || git checkout main || git checkout hg) && \
  72. # git branch -D rm_detached_head && \
  73. # (git reset --hard remotes/origin/master || git reset --hard remotes/origin/main || git reset --hard remotes/origin/hg)
  74. git submodule foreach --recursive zsh -c 'git fetch -a && git checkout -b rm_detached_head && (git checkout master || git checkout main || git checkout hg) && git branch -D rm_detached_head && (git reset --hard remotes/origin/master || git reset --hard remotes/origin/main || git reset --hard remotes/origin/hg)'
  75. }
  76. compile_ycm() {
  77. echo "Compiling YouCompleteMe"
  78. cd "$DIR"/vim/bundle/YouCompleteMe
  79. ./install.py --ts-completer --clang-completer --clangd-completer --cs-completer --rust-completer
  80. cd "$DIR"
  81. }
  82. compile_exctags() {
  83. brew install --HEAD universal-ctags/universal-ctags/universal-ctags
  84. }
  85. case "$1" in
  86. -a|--all)
  87. install_dotfiles
  88. update_git_submodules
  89. compile_ycm
  90. compile_exctags
  91. ;;
  92. -i|--install_dotfiles)
  93. install_dotfiles
  94. ;;
  95. -g|--update_git_submodules)
  96. update_git_submodules
  97. ;;
  98. -y|--compile_ycm)
  99. compile_ycm
  100. ;;
  101. -e|--compile_exctags)
  102. compile_exctags
  103. ;;
  104. *)
  105. echo "Usage: manage_dotfiles <option>"
  106. echo "Options:"
  107. echo " -i --install_dotfiles Install dotfiles to home directory"
  108. echo " -g --update_git_submodules Update git submodules"
  109. echo " -y --compile_ycm Compile YouCompleteMe"
  110. echo " -e --compile_exctags Compile Exuberant-ctags"
  111. echo " -a --all All of the above"
  112. ;;
  113. esac