command-not-found.plugin.zsh 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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