Auto replaces commit hash prefix incrementally with lucky-commit by hooking post-commit.
See all demonstrations in this repository's commit history.
In order for this scenario to work, lucky_commit is required to be installed on your machine.
To set up automatically in your local project:
$ curl -sL https://github.com/dwisiswant0/increment-commit-hash/raw/master/setup.sh | bash
This will add a post-commit hook for your git project. So every time you commit something, lucky_commit
will run after it.
Global means it applies to all your git projects and to install it you have to do-it-yourself (DIY) manually.
Add a Bash function for git
alias command inside your .bash_aliases
file:
git() {
command git "${@}"
[[ "${?}" -eq 0 ]] || return
local COUNT=$(command git rev-list HEAD --count 2>/dev/null)
local HASH=$(printf "%07d" "${COUNT}")
[[ "${1}" == "commit" ]] && lucky_commit "${HASH}"
}
For the alias to trigger when you run git
command, you need to either restart the terminal or evaluate directly with:
$ source $HOME/.bash_aliases
After that, the lucky_commit
command will be executed in any git project after git commit
subcommand w/o having to add post-commit hooks in your projects 1-by-1.
Uninstalling
To delete that alias, simply remove those git
function from .bash_aliases
file and restart your terminal session or unaliasing with:
$ unalias git