gitbare_autoadding_files.sh 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/usr/bin/env bash
  2. # Automate adding files to git
  3. config="/usr/bin/git --git-dir=$HOME/.dotfiles.git --work-tree=$HOME"
  4. target_dir=$HOME
  5. E_WRONG_DIR=73
  6. E_WRONG_CHOICE=74
  7. echo "Choose what to add:"
  8. echo "1) Deleted files."
  9. echo "2) Modified files."
  10. echo "3) New files."
  11. echo "4) All files."
  12. read choice
  13. case ${choice} in
  14. 1) what_to_add="deleted:|удалено:";;
  15. 2) what_to_add="modified:|изменено";;
  16. 3) what_to_add="new file:|новый файл";;
  17. 4) what_to_add="deleted:|modified:|new file:|удалено:|изменено:|новый файл:";;
  18. *) echo -e "Wrong choice.\nExit."; exit $E_WRONG_CHOICE;;
  19. esac
  20. if [[ "$PWD" != "$target_dir" ]]
  21. then
  22. echo "Go to the $target_dir (WHERE THE BARE GIT IS)..."
  23. cd $target_dir &>/dev/null
  24. fi
  25. if [[ "$PWD" != "$target_dir" ]]
  26. then
  27. echo "Wrong dir!"
  28. echo "Variable $PWD links to another dir!"
  29. exit $E_WRONG_DIR
  30. fi
  31. for path in $(${config} status | grep -E "${what_to_add}" | awk -F: '{print $2}')
  32. # for path in $(${config} status | grep -E "${what_to_add}" | awk '{print $2}')
  33. # for path in $(${config} status | grep -E "${what_to_add}" | cut -d : -f 2)
  34. do
  35. ${config} add -f ${path}
  36. # ${config} add -f ${path} 2>/dev/null
  37. # echo "\"$path\""
  38. done
  39. echo "Back to the $OLDPWD (PREVIOUS DIR)..."
  40. cd - &>/dev/null
  41. exit 0