├── LICENSE ├── README.md └── command-not-found.plugin.zsh /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2009-2022 Robby Russell and contributors (https://github.com/ohmyzsh/ohmyzsh/contributors) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # command-not-found plugin 2 | 3 | This plugin uses the command-not-found package for zsh to provide suggested packages to be installed if a command cannot be found. 4 | 5 | To use it, add `command-not-found` to the plugins array of your zshrc file: 6 | 7 | ```zsh 8 | plugins=(... command-not-found) 9 | ``` 10 | 11 | An example of how this plugin works in Ubuntu: 12 | ``` 13 | $ mutt 14 | The program 'mutt' can be found in the following packages: 15 | * mutt 16 | * mutt-kz 17 | * mutt-patched 18 | Try: sudo apt install 19 | ``` 20 | 21 | ### Supported platforms 22 | 23 | It works out of the box with the command-not-found packages for: 24 | 25 | - [Ubuntu](https://www.porcheron.info/command-not-found-for-zsh/) 26 | - [Debian](https://packages.debian.org/search?keywords=command-not-found) 27 | - [Arch Linux](https://wiki.archlinux.org/index.php/Pkgfile#Command_not_found) 28 | - [Fedora](https://fedoraproject.org/wiki/Features/PackageKitCommandNotFound) 29 | - [NixOS](https://github.com/NixOS/nixpkgs/tree/master/nixos/modules/programs/command-not-found) 30 | - [Termux](https://github.com/termux/command-not-found) 31 | - [SUSE](https://www.unix.com/man-page/suse/1/command-not-found/) 32 | 33 | And 34 | 35 | - [Homebrew](https://github.com/Homebrew/homebrew-command-not-found) 36 | 37 | You can add support for other platforms by submitting a Pull Request. 38 | -------------------------------------------------------------------------------- /command-not-found.plugin.zsh: -------------------------------------------------------------------------------- 1 | ## Platforms with a built-in command-not-found handler init file 2 | 3 | handler=Library/Taps/homebrew/homebrew-command-not-found/handler.sh 4 | for file ( 5 | # Arch Linux. Must have pkgfile installed: https://wiki.archlinux.org/index.php/Pkgfile#Command_not_found 6 | /usr/share/doc/pkgfile/command-not-found.zsh 7 | # Linux (Homebrew): https://github.com/Homebrew/homebrew-command-not-found 8 | /home/linuxbrew/.linuxbrew/Homebrew/$handler 9 | # macOS (classic Homebrew): 10 | /usr/local/Homebrew/$handler 11 | # macOS (M1 Homebrew): 12 | /opt/homebrew/$handler 13 | ); do 14 | if [[ -r "$file" ]]; then 15 | source "$file" 16 | unset file 17 | return 0 18 | fi 19 | done 20 | unset file handler 21 | 22 | 23 | ## Platforms with manual command_not_found_handler() setup 24 | 25 | # Debian and derivatives: https://launchpad.net/ubuntu/+source/command-not-found 26 | if [[ -x /usr/lib/command-not-found || -x /usr/share/command-not-found/command-not-found ]]; then 27 | command_not_found_handler() { 28 | if [[ -x /usr/lib/command-not-found ]]; then 29 | /usr/lib/command-not-found -- "$1" 30 | return $? 31 | elif [[ -x /usr/share/command-not-found/command-not-found ]]; then 32 | /usr/share/command-not-found/command-not-found -- "$1" 33 | return $? 34 | else 35 | printf "zsh: command not found: %s\n" "$1" >&2 36 | return 127 37 | fi 38 | } 39 | fi 40 | 41 | # Fedora: https://fedoraproject.org/wiki/Features/PackageKitCommandNotFound 42 | if [[ -x /usr/libexec/pk-command-not-found ]]; then 43 | command_not_found_handler() { 44 | if [[ -S /var/run/dbus/system_bus_socket && -x /usr/libexec/packagekitd ]]; then 45 | /usr/libexec/pk-command-not-found "$@" 46 | return $? 47 | fi 48 | 49 | printf "zsh: command not found: %s\n" "$1" >&2 50 | return 127 51 | } 52 | fi 53 | 54 | # NixOS: https://github.com/NixOS/nixpkgs/tree/master/nixos/modules/programs/command-not-found 55 | if [[ -x /run/current-system/sw/bin/command-not-found ]]; then 56 | command_not_found_handler() { 57 | /run/current-system/sw/bin/command-not-found "$@" 58 | } 59 | fi 60 | 61 | # Termux: https://github.com/termux/command-not-found 62 | if [[ -x /data/data/com.termux/files/usr/libexec/termux/command-not-found ]]; then 63 | command_not_found_handler() { 64 | /data/data/com.termux/files/usr/libexec/termux/command-not-found "$1" 65 | } 66 | fi 67 | 68 | # SUSE and derivates: https://www.unix.com/man-page/suse/1/command-not-found/ 69 | if [[ -x /usr/bin/command-not-found ]]; then 70 | command_not_found_handler() { 71 | /usr/bin/command-not-found "$1" 72 | } 73 | fi 74 | --------------------------------------------------------------------------------