command-not-found.plugin.zsh 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # Uses the command-not-found package zsh support
  2. # as seen in https://www.porcheron.info/command-not-found-for-zsh/
  3. # this is installed in Ubuntu
  4. if [ -x /usr/lib/command-not-found -o -x /usr/share/command-not-found/command-not-found ]; then
  5. function command_not_found_handler {
  6. # check because c-n-f could've been removed in the meantime
  7. if [ -x /usr/lib/command-not-found ]; then
  8. /usr/lib/command-not-found -- "$1"
  9. return $?
  10. elif [ -x /usr/share/command-not-found/command-not-found ]; then
  11. /usr/share/command-not-found/command-not-found -- "$1"
  12. return $?
  13. else
  14. printf "zsh: command not found: %s\n" "$1" >&2
  15. return 127
  16. fi
  17. return 0
  18. }
  19. fi
  20. # Arch Linux command-not-found support, you must have package pkgfile installed
  21. # https://wiki.archlinux.org/index.php/Pkgfile#.22Command_not_found.22_hook
  22. [[ -e /usr/share/doc/pkgfile/command-not-found.zsh ]] && source /usr/share/doc/pkgfile/command-not-found.zsh
  23. # Fedora command-not-found support
  24. if [ -f /usr/libexec/pk-command-not-found ]; then
  25. command_not_found_handler() {
  26. runcnf=1
  27. retval=127
  28. [ ! -S /var/run/dbus/system_bus_socket ] && runcnf=0
  29. [ ! -x /usr/libexec/packagekitd ] && runcnf=0
  30. if [ $runcnf -eq 1 ]; then
  31. /usr/libexec/pk-command-not-found $@
  32. retval=$?
  33. fi
  34. return $retval
  35. }
  36. fi
  37. # OSX command-not-found support
  38. # https://github.com/Homebrew/homebrew-command-not-found
  39. if [[ -s '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-command-not-found/handler.sh' ]]; then
  40. source '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-command-not-found/handler.sh'
  41. fi
  42. # NixOS command-not-found support
  43. if [ -x /run/current-system/sw/bin/command-not-found ]; then
  44. command_not_found_handler() {
  45. /run/current-system/sw/bin/command-not-found $@
  46. }
  47. fi