zsh 中使用 command-not-found

zsh 中显示 command-not-found 提示信息

问题

ubuntu 20.04
使用zsh的过程中发现,如果输入的命令不存在,只提示

command 'tmux' not found

而在使用bash时,提示会比较完整,

Command 'tmux' not found, but can be installed with:

sudo snap install tmux  # version 2.3, or
sudo apt  install tmux  # version 3.0a-2ubuntu0.1

See 'snap info tmux' for additional versions.

没有提示对于我这种小白是很不友好的。

  1. 一是无法准确快速地确定问题的来源,可能是环境变量的配置问题,也可能是没有安装相应的软件,也可能是软件本身的问题,排除起来比较麻烦
  2. 二是对于那些不常用的软件包,无法准确记忆包名,可能会造成安装错或者找不到软件包
    为了更加方便的使用,该如何解决这个问题呢?

解决思路

一、溯源

既然bash可以用,那就先看看bash是如何实现的
.bashrc 中发现了 /etc/bash.bashrc ==>
查看 bash.bashrc ==>

 # if the command-not-found package is installed, use it

二、README
https://packages.ubuntu.com/focal/command-not-found
找到源码包,解压,README

#Command-not-found

This application implements the command-not-found spec at:
https://wiki.ubuntu.com/CommandNotFoundMagic

If you want automatic prompts to install the package, set
COMMAND_NOT_FOUND_INSTALL_PROMPT in your environment.

To use it in bash, please add the following line to your .bashrc file:
. /etc/bash_command_not_found

To use it in zsh, please add the following line to your .zshrc file:
. /etc/zsh_command_not_found
Note that it overrides the preexec and precmd functions, in case you have
defined your own.

哦,原来如此,

To use it in zsh, please add the following line to your .zshrc file:
. /etc/zsh_command_not_found

添加之后,完美显示提示信息

猜你喜欢

转载自blog.csdn.net/qq_16056397/article/details/108869587