fa1911f89eab6d8d753e302546c6ecd5d0db9e08
- Author
- 赵崇延 <47052088+ZhaoChongyan@users.noreply.github.com>
- Committer
- GitHub <noreply@github.com>
- Date
Message
fix(command-not-found): show error in Ubuntu when no package is found (#9418)
Diff
1diff --git a/plugins/command-not-found/command-not-found.plugin.zsh b/plugins/command-not-found/command-not-found.plugin.zsh
2index 81d76e6386a50c17dfa161f441cd8b1221329522..aea1e1b4cde90cb417cd58e6a66a22ffdb7f4d4e 100644
3--- a/plugins/command-not-found/command-not-found.plugin.zsh
4+++ b/plugins/command-not-found/command-not-found.plugin.zsh
5@@ -2,7 +2,22 @@
6 # as seen in https://www.porcheron.info/command-not-found-for-zsh/
7 # this is installed in Ubuntu
8
9-[[ -e /etc/zsh_command_not_found ]] && source /etc/zsh_command_not_found
10+if [ -x /usr/lib/command-not-found -o -x /usr/share/command-not-found/command-not-found ]; then
11+ function command_not_found_handler {
12+ # check because c-n-f could've been removed in the meantime
13+ if [ -x /usr/lib/command-not-found ]; then
14+ /usr/lib/command-not-found -- "$1"
15+ return $?
16+ elif [ -x /usr/share/command-not-found/command-not-found ]; then
17+ /usr/share/command-not-found/command-not-found -- "$1"
18+ return $?
19+ else
20+ printf "zsh: command not found: %s\n" "$1" >&2
21+ return 127
22+ fi
23+ return 0
24+ }
25+fi
26
27 # Arch Linux command-not-found support, you must have package pkgfile installed
28 # https://wiki.archlinux.org/index.php/Pkgfile#.22Command_not_found.22_hook
29@@ -10,13 +25,12 @@
30
31 # Fedora command-not-found support
32 if [ -f /usr/libexec/pk-command-not-found ]; then
33- command_not_found_handler () {
34+ command_not_found_handler() {
35 runcnf=1
36 retval=127
37 [ ! -S /var/run/dbus/system_bus_socket ] && runcnf=0
38 [ ! -x /usr/libexec/packagekitd ] && runcnf=0
39- if [ $runcnf -eq 1 ]
40- then
41+ if [ $runcnf -eq 1 ]; then
42 /usr/libexec/pk-command-not-found $@
43 retval=$?
44 fi
45@@ -32,7 +46,7 @@ fi
46
47 # NixOS command-not-found support
48 if [ -x /run/current-system/sw/bin/command-not-found ]; then
49- command_not_found_handler () {
50+ command_not_found_handler() {
51 /run/current-system/sw/bin/command-not-found $@
52 }
53 fi