Is there a way to intercept the "command not found" error in ZSH? I've seen this is possible in bash apparently, but I couldn't find anything about doing it in zsh.
Asked
Active
Viewed 2,192 times
1 Answers
10
There is; it's the same as in bash, you make a function named command_not_found_handler. It'll be passed all the arguments that were given in the shell
$ foobar baz
zsh: command not found: foobar
$ function command_not_found_handler() {echo "You tried to run $1 with arg $2";}
$ foobar baz
You tried to run foobar with arg baz
Michael Mrozek
- 91,316
- 38
- 238
- 232