command-not-found.plugin.zsh 2.2 KB

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