start 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #!/bin/bash
  2. dot_dir=$HOME/.dofiles
  3. repo="https://git.capella.pro/capella/dotfiles.git"
  4. set -ex
  5. trap popd EXIT
  6. mkdir -pv $dot_dir
  7. pushd $dot_dir
  8. sub_help(){
  9. echo "Usage: $ProgName <subcommand> [options]\n"
  10. echo "Subcommands:"
  11. echo " sync <dot_file_to_add> add a dotfyle to sync"
  12. echo ""
  13. echo "For help with each subcommand run:"
  14. echo "$ProgName <subcommand> -h|--help"
  15. echo ""
  16. }
  17. sub_sync(){
  18. if [[ ! -d $dot_dir/dotfiles/.git ]]; then
  19. git clone $repo
  20. pushd dotfiles
  21. git submodule init
  22. git submodule update
  23. popd
  24. fi
  25. mkdir -p dotfiles/dots
  26. cd dotfiles/dots
  27. git pull
  28. if [ ! -z "$1" ]; then
  29. real_path=$(realpath $1)
  30. to_copy=${real_path#*$HOME}
  31. cp -R $real_path $(pwd)$to_copy
  32. rm -rf $real_path
  33. echo "${to_copy/\//}" >> ../to_sync
  34. fi
  35. cd ..
  36. git add .
  37. if git commit -am "$(date)"; then
  38. git remote add origin $repo || true
  39. git push -u origin master
  40. fi
  41. while read p; do
  42. destination="$HOME/$p"
  43. rm -rf $destination
  44. ln -s "$dot_dir/dotfiles/dots/$p" $(dirname $destination)
  45. done <to_sync
  46. }
  47. subcommand=$1
  48. case $subcommand in
  49. "" | "-h" | "--help")
  50. sub_help
  51. ;;
  52. *)
  53. shift
  54. sub_${subcommand} $@
  55. if [ $? = 127 ]; then
  56. echo "Error: '$subcommand' is not a known subcommand." >&2
  57. echo " Run '$ProgName --help' for a list of known subcommands." >&2
  58. exit 1
  59. fi
  60. ;;
  61. esac