zshでcommand-not-foundを使用する

zshに表示されるコマンドが見つかりませんプロンプト情報

問題

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. 2つ目は、あまり使用されないパッケージの場合、パッケージ名を正確に記憶できないため、インストールエラーが発生したり、パッケージが見つからなかったりすることです。
    より便利に使用するには、この問題を解決する方法を教えてください。

ソリューション

一つ、トレーサビリティ

bashは可能であるため、bashを実現する方法を見てみましょう
。bashrcが見つかりました/etc/bash.bashrc ==>
表示bash.bashrc ==>

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

2. 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