Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to customize command not found style in zsh

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

like image 596
Justin Avatar asked Nov 18 '25 19:11

Justin


1 Answers

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 $?.

like image 54
A. Guy Avatar answered Nov 21 '25 10:11

A. Guy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!