gitbare_autoadding_files.sh 992 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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) All files."
  11. read choice
  12. case ${choice} in
  13. 1) what_to_add="deleted:|удалено:";;
  14. 2) what_to_add="modified:|изменено:";;
  15. 3) what_to_add="deleted:|modified:|удалено:|изменено:";;
  16. *) echo -e "Wrong choice.\nExit."; exit $E_WRONG_CHOICE;;
  17. esac
  18. echo "Go to the $target_dir (WHERE THE BARE GIT IS)..."
  19. cd $target_dir &>/dev/null
  20. if [[ "$PWD" != "$target_dir" ]]
  21. then
  22. echo "Wrong dir!"
  23. echo "Variable $PWD links to another dir!"
  24. exit $E_WRONG_DIR
  25. fi
  26. for path in $(${config} status | grep -E "${what_to_add}" | awk '{print $2}')
  27. do
  28. ${config} add -f ${path}
  29. # ${config} add -f ${path} 2>/dev/null
  30. # echo $path
  31. done
  32. echo "Back to the $OLDPWD (PREVIOUS DIR)..."
  33. cd - &>/dev/null
  34. exit 0