manage_dotfiles.sh 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. mkdir -p $HOME/.config/{,xfce4/xfconf/xfce-perchannel-xml/xfce4-notifyd.xml/}
  43. confs=(
  44. 'ackrc'
  45. 'ag-ignore'
  46. 'bashrc'
  47. 'fehbg'
  48. 'gitconfig'
  49. 'gitignore'
  50. 'git_template'
  51. 'gtkrc-2.0'
  52. 'tmux.conf'
  53. 'vim'
  54. 'vimrc'
  55. 'xinitrc'
  56. 'zshrc'
  57. 'Xmodmap'
  58. 'Xresources'
  59. 'xbindkeysrc'
  60. 'conkyinit'
  61. 'config/conky'
  62. 'config/openbox'
  63. 'config/tint2'
  64. 'config/touchegg'
  65. 'config/awesome'
  66. 'config/xfce4/xfconf/xfce-perchannel-xml/xfce4-notifyd.xml'
  67. )
  68. for conf in ${confs[@]}; do
  69. echo "Linking $conf to $HOME/.$conf"
  70. link "$HOME" "$conf"
  71. done
  72. # For neovim
  73. ln -sn $DIR/vim $HOME/.config/nvim
  74. ln -sn $DIR/vimrc $HOME/.config/nvim/init.vim
  75. # Finish up linking and directory stuff
  76. ln -fsn "$DIR"/vim/pathogen/autoload "$DIR"/vim/
  77. mkdir -p "$DIR"/vim/tmp/{backup,swap,undo}
  78. if prompt "Install airline glyphs?" N; then
  79. yay -S powerline-fonts-git
  80. fi
  81. mkdir -p "$DIR"/vim/tmp/{backup,swap,undo,view}
  82. }
  83. update_git_submodules() {
  84. git submodule update --init --recursive
  85. #git submodule foreach --recursive git reset --hard origin/master
  86. #git submodule foreach --recursive git pull origin master
  87. #git submodule foreach git submodule update --init --recursive
  88. 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)'
  89. }
  90. compile_ycm() {
  91. echo "Compiling YouCompleteMe"
  92. if prompt "Install boost (required for YCM)?" N; then
  93. yay -S boost
  94. fi
  95. cd "$DIR"/vim/bundle/YouCompleteMe
  96. ./install.py --ts-completer --clang-completer --clangd-completer --cs-completer --rust-completer --java-completer
  97. cd "$DIR"
  98. }
  99. compile_exctags() {
  100. yay -S universal-ctags-git
  101. }
  102. case "$1" in
  103. -a|--all)
  104. install_dotfiles
  105. update_git_submodules
  106. compile_ycm
  107. compile_exctags
  108. ;;
  109. -i|--install_dotfiles)
  110. install_dotfiles
  111. ;;
  112. -g|--update_git_submodules)
  113. update_git_submodules
  114. ;;
  115. -y|--compile_ycm)
  116. compile_ycm
  117. ;;
  118. -e|--compile_exctags)
  119. compile_exctags
  120. ;;
  121. *)
  122. echo "Usage: manage_dotfiles <option>"
  123. echo "Options:"
  124. echo " -i --install_dotfiles Install dotfiles to home directory"
  125. echo " -g --update_git_submodules Update git submodules"
  126. echo " -y --compile_ycm Compile YouCompleteMe"
  127. echo " -e --compile_exctags Compile Exuberant-ctags"
  128. echo " -a --all All of the above"
  129. ;;
  130. esac