How can I make git commit
call a custom wrapper shellscript I've written (~/.gitcommit
for example), but all other git
commands are just passed to git like normal.
I am trying as pointed out by https://superuser.com/a/175802/325613
preexec () {
echo preexecing "$1"
if [[ "$1" =~ ^[:space:]*git[:space:]+commit[:space:].* ]]; then
echo git commit detected
fi
}
preexec_invoke_exec () {
[ -n "$COMP_LINE" ] && return # do nothing if completing
[ "$BASH_COMMAND" = "$PROMPT_COMMAND" ] && return # don't cause a preexec for $PROMPT_COMMAND
local this_command=`HISTTIMEFORMAT= history 1 | sed -e "s/^[ ]*[0-9]*[ ]*//"`;
preexec "$this_command"
}
trap 'preexec_invoke_exec' DEBUG
but this prints like this
$ git commit
preexecing git commit
fatal: not a git repository (or any of the parent directories): .git
$ git commit with some args
preexecing git commit with some args
fatal: not a git repository (or any of the parent directories): .git
$ git commit now now now
preexecing git commit now now now
fatal: not a git repository (or any of the parent directories): .git
$ git commit space
preexecing git commit space
fatal: not a git repository (or any of the parent directories): .git
It seems my regex is never matching. Why?