You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
2.0 KiB

  1. #!/usr/bin/env bash
  2. #
  3. # A script to convert the local system to use my dotfiles my local dotfiles over
  4. # the provided ones already on the system. This script will backup any of the
  5. # existing dot files, before linking to the ones in this repository.
  6. #
  7. # Helper Functions
  8. # Make a backup of the existing file if it exists
  9. # Then link to our supplied dotfile
  10. link() {
  11. # Only make a backup if an existing file is there and is not a link
  12. if [ -f "$1/$2" ] && [ ! -L "$1/$2" ]; then
  13. cp "$1/$2" "$1/$2.old"
  14. echo "Backed up original $2 to $1/$2.old"
  15. fi
  16. ln -sf "$PWD/$3" "$1/$2"
  17. }
  18. link_dir() {
  19. # Only make a backup if an existing directory is there and is not a link
  20. if [ -d "$1/$2" ] && [ ! -L "$1/$2" ]; then
  21. mv "$1/$2" "$1/$2.old"
  22. echo "Backed up original $2 to $1/$2.old"
  23. fi
  24. ln -sf "$3" "$1/$2"
  25. }
  26. set -x
  27. set -e
  28. # Configure .vimrc
  29. link "$HOME" ".vimrc" "vimrc"
  30. # Download pathogen if it doesn't exist already
  31. VIM_AUTOLOAD=$HOME/.vim/autoload
  32. mkdir -p $VIM_AUTOLOAD
  33. if [ ! -f "$VIM_AUTOLOAD/pathogen.vim" ]; then
  34. curl -LSso $VIM_AUTOLOAD/pathogen.vim https://tpo.pe/pathogen.vim
  35. fi
  36. # Configure Pathogen Plugins
  37. VIM_BUNDLE=$HOME/.vim/bundle
  38. mkdir -p $VIM_BUNDLE
  39. plugins=($(ls -d $PWD/.vim/bundle/* | tr -s ' '))
  40. for plugin in ${plugins[@]}; do
  41. parts=($(echo "$plugin" | tr '/' ' '))
  42. plugin_name=${parts[-1]}
  43. link_dir $VIM_BUNDLE $plugin_name $plugin
  44. done
  45. # Configure .gitconfig
  46. link "$HOME" ".gitconfig" "gitconfig"
  47. # Configure .zshrc
  48. link "$HOME" ".zshrc" "zshrc"
  49. # Create an auto updater for the dotfiles
  50. if [ ! -f "$HOME/.update_dotfiles.sh" ]; then
  51. echo "#!/usr/bin/env sh" > $HOME/.update_dotfiles.sh
  52. echo "echo 'Updating dotfiles'" >> $HOME/.update_dotfiles.sh
  53. echo "cd $PWD" >> $HOME/.update_dotfiles.sh
  54. echo "git checkout master" >> $HOME/.update_dotfiles.sh
  55. echo "git pull" >> $HOME/.update_dotfiles.sh
  56. echo "git submodule update" >> $HOME/.update_dotfiles.sh
  57. chmod +x $HOME/.update_dotfiles.sh
  58. fi