autocommit.sh 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #! /bin/bash
  2. # Do automatic git-commit to any changes in a diredtory
  3. #
  4. # This is intended to be used with "orglinks.sh" which creates
  5. # hard links for all *.org files under, e.g., $HOME to a
  6. # parcicular directory, e.g. ~/orgfiles
  7. #
  8. # Usage: autocommit DIR
  9. # This is bash, be safe
  10. set -u
  11. set -e
  12. # pull in my error, warning, etc.
  13. source ~/lib/bash/bashutils.sh
  14. # Directory provided as an argument
  15. dir="${1:-$HOME/orgfiles}"
  16. # Check if the provided directory exists
  17. if [ ! -d "$dir" ]; then
  18. error "Error: Directory '$dir' does not exist."
  19. fi
  20. cd $dir
  21. # make sure it is a git root dir
  22. if [ -d $dir/.git ]; then
  23. :
  24. else
  25. info initializing git in $dir
  26. git init .
  27. fi
  28. # Git commit changes if any
  29. if [[ $(git status --porcelain) ]]; then
  30. # Changes exist, so commit them
  31. info files to be added:
  32. git ls-files -o *.org
  33. info files changed:
  34. git ls-files -m *.org
  35. # Add all org files
  36. info adding all .org files
  37. git add *.org
  38. # # get rid of anytthing that's not an .org file
  39. # git clean -f
  40. git commit -am "Autocommit `date`"
  41. info "Changes committed."
  42. else
  43. # No changes to commit
  44. info "No changes to commit."
  45. fi