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. fi
  21. mkdir -p dotfiles/dots
  22. cd dotfiles/dots
  23. git pull
  24. if [ ! -z "$1" ]; then
  25. real_path=$(realpath $1)
  26. if [[ ! -d $real_path ]]; then
  27. echo "$real_path is not a dir!"
  28. exit 0
  29. fi
  30. to_copy=${real_path#*$HOME}
  31. mkdir -p $(pwd)$to_copy
  32. cp -R $real_path $(pwd)$to_copy
  33. rm -rf $real_path
  34. echo "${to_copy/\//}" >> ../to_sync
  35. fi
  36. cd ..
  37. git add .
  38. if git commit -am "$(date)"; then
  39. git push
  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