1

How to customize command not found in zsh (MacOS)

For example:

MacBook-Pro: ~ justin$ lll
zsh: command not found: lll

To

MacBook-Pro: ~ justin$ lll
zsh: WTFFFFF command not found: lll

There is a thread discuss about the case in bash, but i can't find anything like command-not-found in ~/zshrc, /private/etc/zshrc, and /private/etc/zprofile

Justin
  • 15
  • 4

1 Answers1

2

zsh looking for the function command_not_found_handler in the zshrc file (instead of command_not_found_handle of bash).

Add to your ~/.zshrc file something like:

command_not_found_handler() {
    echo "zsh: WTFFFFF command not found: $@"
    return 127
}

or customize it further. Notice the return 127 line: the default command not found handler function returns the exit code 127 so this way you can keep this behavior. You can test the exit code with echo $?.

A. Guy
  • 500
  • 1
  • 3
  • 10
  • I also found [this](https://github.com/Tireg/zsh-macos-command-not-found/blob/master/macos-command-not-found.plugin.zsh) project that you can use – A. Guy Nov 26 '21 at 07:39