command-not-found.plugin.zsh 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. # 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. /home/linuxbrew/.linuxbrew/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. ## Platforms with manual command_not_found_handler() setup
  18. # Debian and derivatives: https://launchpad.net/ubuntu/+source/command-not-found
  19. if [[ -x /usr/lib/command-not-found || -x /usr/share/command-not-found/command-not-found ]]; then
  20. command_not_found_handler() {
  21. if [[ -x /usr/lib/command-not-found ]]; then
  22. /usr/lib/command-not-found -- "$1"
  23. return $?
  24. elif [[ -x /usr/share/command-not-found/command-not-found ]]; then
  25. /usr/share/command-not-found/command-not-found -- "$1"
  26. return $?
  27. else
  28. printf "zsh: command not found: %s\n" "$1" >&2
  29. return 127
  30. fi
  31. }
  32. fi
  33. # Fedora: https://fedoraproject.org/wiki/Features/PackageKitCommandNotFound
  34. if [[ -x /usr/libexec/pk-command-not-found ]]; then
  35. command_not_found_handler() {
  36. if [[ -S /var/run/dbus/system_bus_socket && -x /usr/libexec/packagekitd ]]; then
  37. /usr/libexec/pk-command-not-found "$@"
  38. return $?
  39. fi
  40. printf "zsh: command not found: %s\n" "$1" >&2
  41. return 127
  42. }
  43. fi
  44. # NixOS: https://github.com/NixOS/nixpkgs/tree/master/nixos/modules/programs/command-not-found
  45. if [[ -x /run/current-system/sw/bin/command-not-found ]]; then
  46. command_not_found_handler() {
  47. /run/current-system/sw/bin/command-not-found "$@"
  48. }
  49. fi
  50. # Termux: https://github.com/termux/command-not-found
  51. if [[ -x /data/data/com.termux/files/usr/libexec/termux/command-not-found ]]; then
  52. command_not_found_handler() {
  53. /data/data/com.termux/files/usr/libexec/termux/command-not-found "$1"
  54. }
  55. fi
  56. # SUSE and derivates: https://www.unix.com/man-page/suse/1/command-not-found/
  57. if [[ -x /usr/bin/command-not-found ]]; then
  58. command_not_found_handler() {
  59. /usr/bin/command-not-found "$1"
  60. }
  61. fi