My scripts for startup, dmenu, and the command line
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.

73 lines
1.4 KiB

  1. #!/bin/sh
  2. pull_backup() {
  3. check_args $# 2
  4. if [ ! -d "$BACKUPS_PATH/$2" ]; then
  5. invalid_path_msg "$1:$2"
  6. return 1;
  7. fi
  8. git -C $BACKUPS_PATH/$2 pull $1
  9. }
  10. push_backup() {
  11. check_args $# 2
  12. if [ ! -d "$BACKUPS_PATH/$2" ]; then
  13. invalid_path_msg "$1:$2"
  14. return 1;
  15. fi
  16. git -C $BACKUPS_PATH/$2 push $1
  17. }
  18. overwrite_local() {
  19. if [ ! -e "$BACKUPS_PATH/$1/$2" ]; then
  20. printf "The backup path does not exist\n"
  21. return 1;
  22. fi
  23. case "$1" in
  24. configs) cp -r "$BACKUPS_PATH/$1/$2" "$XDG_CONFIG_HOME/$2";;
  25. macros) cp -r "$BACKUPS_PATH/$1/$2" "$HOME/Macros/$2";;
  26. *) invalid_path_msg "$1"; return 1;;
  27. esac
  28. }
  29. overwrite_backup() {
  30. if [ git diff --stat $BACKUPS_PATH/$1 ]; then
  31. printf "There are uncommited changes in $1\n"
  32. return 1
  33. fi
  34. case "$1" in
  35. configs) cp -r "$XDG_CONFIG_HOME/$2" "$BACKUPS_PATH/$1/$2";;
  36. macros) cp -r "$HOME/Macros/$2" "$BACKUPS_PATH/$1/$2";;
  37. *) invalid_path_msg "$1"; return 1;;
  38. esac
  39. }
  40. invalid_path_msg() {
  41. printf "That path is invalid. $@\n"
  42. }
  43. check_args() {
  44. if [ $1 -ne $2 ]; then
  45. printf "Invalid number of arguments. Expected $2\n"
  46. exit;
  47. fi
  48. return 0;
  49. }
  50. case "$1" in
  51. pull-backup)
  52. case "$2" in
  53. configs) pull_backup configs;;
  54. macros) pull_backup macros;;
  55. esac
  56. ;;
  57. overwrite-local) overwrite_local $2 $3;;
  58. overwrite-backup) overwrite_backup $2 $3;;
  59. pull-backup) pull_backup $2 $3;;
  60. push-backup) push_backup $2 $3;;
  61. push-backup) overwrite_backup $2 $3;;
  62. *) printf "No such option\n";;
  63. esac