How do I tell my zsh to automatically try a command with git
in front, if the command is not found? E.g. I want to run $ status
and if there is no status
in $PATH
, my zsh should try git status
.
How to call git commands without ‘git ‘ in front
commandgitzsh
Best Answer
This sounds fragile — you could get into the habit into typing
foo
instead ofgit foo
, and then one day a newfoo
command appears andfoo
no longer invokesgit foo
— but it can be done. When a command is not found with normal lookup (alias, function, builtin, executable onPATH
), zsh invokes thecommand_not_found_handler
function (if it's defined). This function receives the command and the command's arguments as its arguments.If you want to do some fancier filtering, the command is in
$1
and its arguments can be referred to as"$@[2,$#]"
.