start 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. to_copy=${real_path#*$HOME}
  26. cp -R $real_path $(pwd)$to_copy
  27. rm -rf $real_path
  28. echo "${to_copy/\//}" >> ../to_sync
  29. fi
  30. cd ..
  31. git add .
  32. if git commit -am "$(date)"; then
  33. git remote add origin $repo || true
  34. git push -u origin master
  35. fi
  36. while read p; do
  37. destination="$HOME/$p"
  38. rm -rf $destination
  39. ln -s "$dot_dir/dotfiles/dots/$p" $(dirname $destination)
  40. done <to_sync
  41. }
  42. subcommand=$1
  43. case $subcommand in
  44. "" | "-h" | "--help")
  45. sub_help
  46. ;;
  47. *)
  48. shift
  49. sub_${subcommand} $@
  50. if [ $? = 127 ]; then
  51. echo "Error: '$subcommand' is not a known subcommand." >&2
  52. echo " Run '$ProgName --help' for a list of known subcommands." >&2
  53. exit 1
  54. fi
  55. ;;
  56. esac