Add this to your .bashrc or similar:
# Add function to catch arguments.
check_git() {
python git-check-before-add.py $* && git $*
}
# Replace git command
alias git=check_git
# Restore autocomplete
compdef git_check=git
| #!/usr/bin/env python | |
| import sys | |
| def main(): | |
| """ | |
| Main entry point. | |
| """ | |
| if "commit -am" in " ".join(sys.argv).lower(): | |
| sys.stdout.write("Confirm add-then-commit [yN]: ") | |
| if sys.stdin.read(1).lower() != "y": | |
| return 1 | |
| # E.g. `python git-check-add.py` | |
| if __name__ == "__main__": | |
| sys.exit(main()) |