fork/fish-shell
git clone https://git.julia.blue/fork/fish-shell
d601ceb55
master
1### Command-not-found handlers 2# This can be overridden by defining a new fish_command_not_found function 3 4function fish_command_not_found 5__fish_default_command_not_found_handler $argv 6end 7 8if not status is-interactive 9exit 10end 11 12# Read the OS/Distro from /etc/os-release. 13# This has a "ID=" line that defines the exact distribution, 14# and an "ID_LIKE=" line that defines what it is derived from or otherwise like. 15# For our purposes, we use both. 16set -l os 17if test -r /etc/os-release 18set os( string replace -rf'^ID(?:_LIKE)?\s*=(.*)' '$1' < /etc/os-release| 19string trim -c'\'"' | string split" " ) 20end 21 22# If an old handler already exists, defer to that. 23if functions -q __fish_command_not_found_handler 24function fish_command_not_found 25# The fish_command_not_found event was removed in fish 3.2.0, 26# and future versions of fish will just call a function called "fish_command_not_found". 27# You have defined a custom handler, we suggest renaming it to "fish_command_not_found". 28__fish_command_not_found_handler $argv 29end 30# First check if we are on OpenSUSE since SUSE's handler has no options 31# but the same name and path as Ubuntu's. 32else if contains -- suse$os || contains -- sles$os && type -q command-not-found 33function fish_command_not_found 34command-not-found $argv [ 1 ] 35end 36# Check for Fedora's handler 37else if test -f /usr/libexec/pk-command-not-found 38function fish_command_not_found 39/usr/libexec/pk-command-not-found $argv 40end 41# Check in /usr/lib, where Ubuntu places this command 42else if test -f /usr/lib/command-not-found 43function fish_command_not_found 44/usr/lib/command-not-found --$argv [ 1 ] 45end 46# Check for NixOS handler 47else if test -f /run/current-system/sw/bin/command-not-found 48function fish_command_not_found 49/run/current-system/sw/bin/command-not-found $argv 50end 51# Ubuntu Feisty places this command in the regular path instead 52else if type -q command-not-found 53function fish_command_not_found 54command-not-found --$argv [ 1 ] 55end 56# pkgfile is an optional, but official, package on Arch Linux 57# it ships with example handlers for bash and zsh, so we'll follow that format 58else if type -q pkgfile 59function fish_command_not_found 60set -l __packages( pkgfile --binaries --verbose --$argv [ 1 ] 2> /dev/null) 61if test $status -eq 0 62printf "%s may be found in the following packages:\n" " $argv [ 1 ] " 63printf " %s\n" $__packages 64else 65__fish_default_command_not_found_handler $argv [ 1 ] 66end 67end 68# pacman is too slow, see #7841. 69# else if type -q pacman 70# function fish_command_not_found 71# set -l paths $argv[1] 72# # If we've not been given an absolute path, try $PATH as the starting point, 73# # otherwise pacman will try *every path*, and e.g. bash-completion 74# # isn't helpful. 75# string match -q '/*' -- $argv[1]; or set paths $PATH/$argv[1] 76# # Pacman only prints the path, so we still need to print the error. 77# __fish_default_command_not_found_handler $argv[1] 78# pacman -F $paths 79# end 80end