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.

97 lignes
2.1 KiB

  1. #!/bin/sh
  2. BACKUPS_PATH=$HOME/Backups
  3. gitcmd() {
  4. #First arg should be the name of the subdirectory, second arg should be command
  5. check_args $# 2
  6. if [ ! -d "$BACKUPS_PATH/$1" ]; then
  7. invalid_path_msg "$1"
  8. return 1;
  9. fi
  10. git -C $BACKUPS_PATH/$1 $2
  11. printf "The command succeded\n"
  12. }
  13. git_clone_backup() {
  14. check_args $# 2
  15. git -C $BACKUPS_PATH clone $1:Backups/$2
  16. }
  17. git_clone_proj() {
  18. check_args $# 2
  19. git -C $HOME/Projects clone ssh://$1/~/Projects/$2
  20. }
  21. bdiff() {
  22. check_args $# 2
  23. if [ ! -d "$BACKUPS_PATH/$1" ]; then
  24. invalid_path_msg "$1"
  25. return 1;
  26. fi
  27. case "$1" in
  28. configs) vimdiff "$BACKUPS_PATH/$1/$2" "$XDG_CONFIG_HOME/$2";;
  29. macros) vimdiff "$BACKUPS_PATH/$1/$2" "$HOME/Macros/$2";;
  30. global_vim) vimdiff "$BACKUPS_PATH/$1/$2" "/usr/share/vim/$2";;
  31. *) invalid_path_msg "$1"; return 1;;
  32. esac
  33. }
  34. overwrite_local() {
  35. if [ ! -e $BACKUPS_PATH/$1/$2 ]; then
  36. printf "The backup path $BACKUPS_PATH/$1/$2 does not exist\n"
  37. return 1;
  38. fi
  39. case "$1" in
  40. configs) cp -r $BACKUPS_PATH/$1/$2 "$XDG_CONFIG_HOME/";;
  41. macros) cp -r $BACKUPS_PATH/$1/$2 "$HOME/Macros/";;
  42. *) invalid_path_msg "$1"; return 1;;
  43. esac
  44. printf "local overwrite successful\n"
  45. }
  46. overwrite_lmacros() {
  47. overwrite_local macros '*'
  48. }
  49. overwrite_backup() {
  50. if [ git diff --stat $BACKUPS_PATH/$1 ]; then
  51. printf "There are uncommited changes in $1\n"
  52. return 1
  53. fi
  54. case "$1" in
  55. config) cp -r $XDG_CONFIG_HOME/$2 "$BACKUPS_PATH/$1/$2";;
  56. macros) cp -r $HOME/Macros/$2 "$BACKUPS_PATH/$1/$2";;
  57. *) invalid_path_msg "$1"; return 1;;
  58. esac
  59. printf "backup overwrite successful\n"
  60. }
  61. invalid_path_msg() {
  62. printf "That path is invalid. $@\n"
  63. }
  64. check_args() {
  65. if [ $1 -ne $2 ]; then
  66. printf "Invalid number of arguments. Expected $2\n"
  67. exit;
  68. fi
  69. return 0;
  70. }
  71. case "$1" in
  72. pull-backup)
  73. case "$2" in
  74. configs) pull_backup configs;;
  75. macros) pull_backup macros;;
  76. esac
  77. ;;
  78. overwrite-local) overwrite_local $2 $3;;
  79. overwrite-backup) overwrite_backup $2 $3;;
  80. gitcmd) gitcmd "$2" "$3";;
  81. push-backup) overwrite_backup $2 $3;;
  82. bclone) git_clone_backup "$2" "$3";;
  83. pclone) git_clone_proj "$2" "$3";;
  84. bdiff) bdiff $2 "$3";;
  85. *) printf "No such option\n";;
  86. esac