時々、bashプロンプトが何をすべきかを提案するかもしれません。
良い:
The program 'htop' is currently not installed. You can install it by typing:
apt-get install htop
または:
the branch has no upstream branch yet, do git push --set-upstream origin branchname
!!
コードをコピーまたは再入力せずに(最後のコマンドを変更するなど)、提案された操作を直接実行できるコマンド、ショートカット、または置換はありますか?
ベストアンサー1
まず、あなたが提示した例は同じではありません。 UbuntuではCommand Not Found マジックについては後述する。。詳細を追加すると実際に/usr/lib/command-not-found
。
例は次のとおりです。
# /usr/lib/command-not-found htop
The program 'htop' is currently not installed. You can install it by typing:
apt-get install htop
/etc/bash.bashrc
起動時にBashシェルに含まれるパッケージに見つからないコマンドハンドラを定義します。
# if the command-not-found package is installed, use it
if [ -x /usr/lib/command-not-found -o -x /usr/share/command-not-found/command-not-found ]; then
function command_not_found_handle {
# check because c-n-f could've been removed in the meantime
if [ -x /usr/lib/command-not-found ]; then
/usr/lib/command-not-found -- "$1"
return $?
elif [ -x /usr/share/command-not-found/command-not-found ]; then
/usr/share/command-not-found/command-not-found -- "$1"
return $?
else
printf "%s: command not found\n" "$1" >&2
return 127
fi
}
fi
吹くバージョン4以降ではcommand_not_found_handle
コマンドが見つからない場合を処理するための組み込み名です。
という新しい組み込みエラー処理機能があります
command_not_found_handle
。#!/bin/bash4 command_not_found_handle () { # Accepts implicit parameters. echo "The following command is not valid: \""$1\""" echo "With the following argument(s): \""$2\"" \""$3\""" # $4, $5 ... } # $1, $2, etc. are not explicitly passed to the function. bad_command arg1 arg2 # The following command is not valid: "bad_command" # With the following argument(s): "arg1" "arg2"
したがって、短い答えは「いいえ」です。出力を解析し、一種の新機能を生成せずに要求された操作を実行する方法はありません。