start 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. fi
  21. mkdir -p dotfiles/dots
  22. cd dotfiles/dots
  23. if [ ! -z "$1" ]; then
  24. real_path=$(realpath $1)
  25. if [[ ! -d $real_path ]]; then
  26. echo "$real_path is not a dir!"
  27. exit 0
  28. fi
  29. to_copy=${real_path#*$HOME}
  30. mkdir -p $(pwd)$to_copy
  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 push
  39. fi
  40. while read p; do
  41. destination="$HOME/$p"
  42. rm -rf $destination
  43. ln -s "$dot_dir/dotfiles/dots/$p" $(dirname $destination)
  44. done <to_sync
  45. }
  46. subcommand=$1
  47. case $subcommand in
  48. "" | "-h" | "--help")
  49. sub_help
  50. ;;
  51. *)
  52. shift
  53. sub_${subcommand} $@
  54. if [ $? = 127 ]; then
  55. echo "Error: '$subcommand' is not a known subcommand." >&2
  56. echo " Run '$ProgName --help' for a list of known subcommands." >&2
  57. exit 1
  58. fi
  59. ;;
  60. esac