My scripts for startup, dmenu, and the command line
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

65 lignes
1.4 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 $BACKUPS_PATH/$1/$2 does not exist\n"
  15. return 1;
  16. fi
  17. case "$1" in
  18. configs) cp -r "$BACKUPS_PATH/$1/$2" "$XDG_CONFIG_HOME/";;
  19. macros) cp -r "$BACKUPS_PATH/$1/$2" "$HOME/Macros/";;
  20. *) invalid_path_msg "$1"; return 1;;
  21. esac
  22. printf "local overwrite successful\n"
  23. }
  24. overwrite_backup() {
  25. if [ git diff --stat $BACKUPS_PATH/$1 ]; then
  26. printf "There are uncommited changes in $1\n"
  27. return 1
  28. fi
  29. case "$1" in
  30. configs) cp -r "$XDG_CONFIG_HOME/$2" "$BACKUPS_PATH/$1/$2";;
  31. macros) cp -r "$HOME/Macros/$2" "$BACKUPS_PATH/$1/$2";;
  32. *) invalid_path_msg "$1"; return 1;;
  33. esac
  34. printf "backup overwrite successful\n"
  35. }
  36. invalid_path_msg() {
  37. printf "That path is invalid. $@\n"
  38. }
  39. check_args() {
  40. if [ $1 -ne $2 ]; then
  41. printf "Invalid number of arguments. Expected $2\n"
  42. exit;
  43. fi
  44. return 0;
  45. }
  46. case "$1" in
  47. pull-backup)
  48. case "$2" in
  49. configs) pull_backup configs;;
  50. macros) pull_backup macros;;
  51. esac
  52. ;;
  53. overwrite-local) overwrite_local $2 $3;;
  54. overwrite-backup) overwrite_backup $2 $3;;
  55. gitcmd) gitcmd "$2" "$3";;
  56. push-backup) overwrite_backup $2 $3;;
  57. *) printf "No such option\n";;
  58. esac