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.

93 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_backup() {
  47. if [ git diff --stat $BACKUPS_PATH/$1 ]; then
  48. printf "There are uncommited changes in $1\n"
  49. return 1
  50. fi
  51. case "$1" in
  52. config) cp -r "$XDG_CONFIG_HOME/$2" "$BACKUPS_PATH/$1/$2";;
  53. macros) cp -r "$HOME/Macros/$2" "$BACKUPS_PATH/$1/$2";;
  54. *) invalid_path_msg "$1"; return 1;;
  55. esac
  56. printf "backup overwrite successful\n"
  57. }
  58. invalid_path_msg() {
  59. printf "That path is invalid. $@\n"
  60. }
  61. check_args() {
  62. if [ $1 -ne $2 ]; then
  63. printf "Invalid number of arguments. Expected $2\n"
  64. exit;
  65. fi
  66. return 0;
  67. }
  68. case "$1" in
  69. pull-backup)
  70. case "$2" in
  71. configs) pull_backup configs;;
  72. macros) pull_backup macros;;
  73. esac
  74. ;;
  75. overwrite-local) overwrite_local $2 $3;;
  76. overwrite-backup) overwrite_backup $2 $3;;
  77. gitcmd) gitcmd "$2" "$3";;
  78. push-backup) overwrite_backup $2 $3;;
  79. bclone) git_clone_backup "$2" "$3";;
  80. pclone) git_clone_proj "$2" "$3";;
  81. bdiff) bdiff $2 "$3";;
  82. *) printf "No such option\n";;
  83. esac