My scripts for startup, dmenu, and the command line

63 lines
1.3 KiB

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