Enable Command Not Found messages in Zsh

I found out how to allow the "... command not found but can be installed with..." to appear in Oh-my-zsh by adding source /etc/zsh_command_not_found to my .zshrc.

But now, when I type a command that doesn't exist but there isn't a "...can be installed with" message, there is no output, acting as if I entered a command that had no output.

Original (Expected) Behavior:

~$ Non_existant_command
Non_existant_command: command not found
~$

New (Unwanted) Behavior:

~$ Non_existant_command
~$

1 Answer

That appears to be because /etc/zsh_command_not_found invokes /usr/lib/command-not-found with the --no-failure-msg option:

 % cat /etc/zsh_command_not_found
# (c) Zygmunt Krynicki 2007,
# Licensed under GPL, see COPYING for the whole text
#
# This script will look-up command in the database and suggest
# installation of packages available from the repository
if [[ -x /usr/lib/command-not-found ]] ; then if (( ! ${+functions[command_not_found_handler]} )) ; then function command_not_found_handler { [[ -x /usr/lib/command-not-found ]] || return 1 /usr/lib/command-not-found --no-failure-msg -- ${1+"$1"} && : } fi
fi

where

 % /usr/lib/command-not-found --help
Usage: command-not-found [options] <command-name>
Options: --version show program's version number and exit -h, --help show this help message and exit -d DATA_DIR, --data-dir=DATA_DIR use this path to locate data fields --ignore-installed, --ignore-installed ignore local binaries and display the available packages --no-failure-msg don't print '<command-name>: command not found'

If you want the message to show, you can make a local copy of the zsh_command_not_found script, edit it to remove that option, and source that instead.

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like