command-not-found.plugin.zsh
3017 bytes
1## Platforms with a built-in command-not-found handler init file
2
3for file (
4 # Arch Linux. Must have pkgfile installed: https://wiki.archlinux.org/title/Zsh#pkgfile_"command_not_found"_handler
5 /usr/share/doc/pkgfile/command-not-found.zsh
6 # Void Linux: https://codeberg.org/classabbyamp/xbps-command-not-found
7 /usr/share/zsh/plugins/xbps-command-not-found/xbps-command-not-found.zsh
8 # Homebrew: https://github.com/Homebrew/brew/blob/main/docs/Command-Not-Found.md
9 /opt/homebrew/Library/Homebrew/command-not-found/handler.sh
10 /usr/local/Homebrew/Library/Homebrew/command-not-found/handler.sh
11 /home/linuxbrew/.linuxbrew/Homebrew/Library/Homebrew/command-not-found/handler.sh
12 # Old homebrew implementation
13 /opt/homebrew/Library/Taps/homebrew/homebrew-command-not-found/handler.sh
14 /usr/local/Homebrew/Library/Taps/homebrew/homebrew-command-not-found/handler.sh
15 /home/linuxbrew/.linuxbrew/Homebrew/Library/Taps/homebrew/homebrew-command-not-found/handler.sh
16); do
17 if [[ -r "$file" ]]; then
18 source "$file"
19 unset file
20 return 0
21 fi
22done
23unset file
24
25
26## Platforms with manual command_not_found_handler() setup
27
28# Debian and derivatives: https://launchpad.net/ubuntu/+source/command-not-found
29if [[ -x /usr/lib/command-not-found || -x /usr/share/command-not-found/command-not-found ]]; then
30 command_not_found_handler() {
31 if [[ -x /usr/lib/command-not-found ]]; then
32 /usr/lib/command-not-found -- "$1"
33 return $?
34 elif [[ -x /usr/share/command-not-found/command-not-found ]]; then
35 /usr/share/command-not-found/command-not-found -- "$1"
36 return $?
37 else
38 printf "zsh: command not found: %s\n" "$1" >&2
39 return 127
40 fi
41 }
42fi
43
44# Fedora: https://fedoraproject.org/wiki/Features/PackageKitCommandNotFound
45if [[ -x /usr/libexec/pk-command-not-found ]]; then
46 command_not_found_handler() {
47 if [[ -S /var/run/dbus/system_bus_socket && -x /usr/libexec/packagekitd ]]; then
48 /usr/libexec/pk-command-not-found "$@"
49 return $?
50 fi
51
52 printf "zsh: command not found: %s\n" "$1" >&2
53 return 127
54 }
55fi
56
57# NixOS: https://github.com/NixOS/nixpkgs/tree/master/nixos/modules/programs/command-not-found
58if [[ -x /run/current-system/sw/bin/command-not-found ]]; then
59 command_not_found_handler() {
60 /run/current-system/sw/bin/command-not-found "$@"
61 }
62fi
63
64# Termux: https://github.com/termux/command-not-found
65if [[ -x /data/data/com.termux/files/usr/libexec/termux/command-not-found ]]; then
66 command_not_found_handler() {
67 /data/data/com.termux/files/usr/libexec/termux/command-not-found "$1"
68 }
69fi
70
71# SUSE and derivates: https://www.unix.com/man-page/suse/1/command-not-found/
72if [[ -x /usr/bin/command-not-found ]]; then
73 command_not_found_handler() {
74 /usr/bin/command-not-found "$1"
75 }
76fi
77
78# Alpine: https://gitlab.alpinelinux.org/alpine/aports/-/blob/master/main/command-not-found/APKBUILD
79if [[ -x /usr/libexec/command-not-found ]]; then
80 command_not_found_handler() {
81 /usr/libexec/command-not-found "$1"
82 }
83fi