]> src.twobees.de Git - dotfiles.git/blob - stow/oh-my-zsh/.oh-my-zsh/plugins/command-not-found/command-not-found.plugin.zsh
cb8a8989c53602ecc1b0bacf07d665f3b4163f62
[dotfiles.git] / stow / oh-my-zsh / .oh-my-zsh / plugins / command-not-found / command-not-found.plugin.zsh
1 ## Platforms with a built-in command-not-found handler init file
2
3 for file (
4   # Arch Linux. Must have pkgfile installed: https://wiki.archlinux.org/index.php/Pkgfile#Command_not_found
5   /usr/share/doc/pkgfile/command-not-found.zsh
6   # macOS (M1 and classic Homebrew): https://github.com/Homebrew/homebrew-command-not-found
7   /opt/homebrew/Library/Taps/homebrew/homebrew-command-not-found/handler.sh
8   /usr/local/Homebrew/Library/Taps/homebrew/homebrew-command-not-found/handler.sh
9 ); do
10   if [[ -r "$file" ]]; then
11     source "$file"
12     unset file
13     return 0
14   fi
15 done
16 unset file
17
18
19 ## Platforms with manual command_not_found_handler() setup
20
21 # Debian and derivatives: https://launchpad.net/ubuntu/+source/command-not-found
22 if [[ -x /usr/lib/command-not-found || -x /usr/share/command-not-found/command-not-found ]]; then
23   command_not_found_handler() {
24     if [[ -x /usr/lib/command-not-found ]]; then
25       /usr/lib/command-not-found -- "$1"
26       return $?
27     elif [[ -x /usr/share/command-not-found/command-not-found ]]; then
28       /usr/share/command-not-found/command-not-found -- "$1"
29       return $?
30     else
31       printf "zsh: command not found: %s\n" "$1" >&2
32       return 127
33     fi
34   }
35 fi
36
37 # Fedora: https://fedoraproject.org/wiki/Features/PackageKitCommandNotFound
38 if [[ -x /usr/libexec/pk-command-not-found ]]; then
39   command_not_found_handler() {
40     if [[ -S /var/run/dbus/system_bus_socket && -x /usr/libexec/packagekitd ]]; then
41       /usr/libexec/pk-command-not-found "$@"
42       return $?
43     fi
44
45     printf "zsh: command not found: %s\n" "$1" >&2
46     return 127
47   }
48 fi
49
50 # NixOS: https://github.com/NixOS/nixpkgs/tree/master/nixos/modules/programs/command-not-found
51 if [[ -x /run/current-system/sw/bin/command-not-found ]]; then
52   command_not_found_handler() {
53     /run/current-system/sw/bin/command-not-found "$@"
54   }
55 fi
56
57 # Termux: https://github.com/termux/command-not-found
58 if [[ -x /data/data/com.termux/files/usr/libexec/termux/command-not-found ]]; then
59   command_not_found_handler() {
60     /data/data/com.termux/files/usr/libexec/termux/command-not-found "$1"
61   }
62 fi
63
64 # SUSE and derivates: https://www.unix.com/man-page/suse/1/command-not-found/
65 if [[ -x /usr/bin/command-not-found ]]; then
66   command_not_found_handler() {
67     /usr/bin/command-not-found "$1"
68   }
69 fi