mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-30 06:03:49 +08:00
Immediately define command-not-found handler
This skips the weird dance where we'd define a simple handler and then later overwrite with a fancier one, once the first event came in. It turns out that isn't necessary, as it doesn't actually improve startup speed because the checks needed to define fancier handlers are fast. In case we are non-interactive, still define the simple handler, and keep the default handler for users to switch to.
This commit is contained in:
parent
b7fb11cb7f
commit
1a12071a48
|
@ -19,10 +19,9 @@ end
|
|||
|
||||
#
|
||||
# Hook up the default as the principal command_not_found handler
|
||||
# for starting up since finding and executing a real one is not cheap
|
||||
# This will be erased in __fish_command_not_found_setup once we're interactive
|
||||
# in case we are not interactive
|
||||
#
|
||||
function __fish_startup_command_not_found_handler --on-event fish_command_not_found
|
||||
status -i; or function __fish_command_not_found_handler --on-event fish_command_not_found
|
||||
__fish_default_command_not_found_handler $argv
|
||||
end
|
||||
|
||||
|
|
|
@ -171,48 +171,38 @@ function __fish_config_interactive -d "Initializations that should be performed
|
|||
__update_vte_cwd # Run once because we might have already inherited a PWD from an old tab
|
||||
end
|
||||
|
||||
# Remove the startup command_not_found handler since we're done with it
|
||||
functions -e __fish_startup_command_not_found_handler
|
||||
|
||||
# Now install our fancy variant
|
||||
function __fish_command_not_found_setup --on-event fish_command_not_found
|
||||
# Remove fish_command_not_found_setup so we only execute this once
|
||||
functions --erase __fish_command_not_found_setup
|
||||
|
||||
# If the user defined a handler, it takes precedence
|
||||
# It does not need to be executed because it's been defined before the event
|
||||
if type -q __fish_command_not_found_handler
|
||||
return 0
|
||||
end
|
||||
### Command-not-found handlers
|
||||
# This can be overridden by defining a new __fish_command_not_found_handler function
|
||||
if not type -q __fish_command_not_found_handler
|
||||
# First check if we are on OpenSUSE since SUSE's handler has no options
|
||||
# and expects first argument to be a command and second database
|
||||
# also check if there is command-not-found command.
|
||||
if begin; test -f /etc/SuSE-release; and type -q -p command-not-found; end
|
||||
if test -f /etc/SuSE-release; and type -q -p command-not-found
|
||||
function __fish_command_not_found_handler --on-event fish_command_not_found
|
||||
/usr/bin/command-not-found $argv[1]
|
||||
end
|
||||
# Check for Fedora's handler
|
||||
# Check for Fedora's handler
|
||||
else if test -f /usr/libexec/pk-command-not-found
|
||||
function __fish_command_not_found_handler --on-event fish_command_not_found
|
||||
/usr/libexec/pk-command-not-found $argv[1]
|
||||
end
|
||||
# Check in /usr/lib, this is where modern Ubuntus place this command
|
||||
# Check in /usr/lib, this is where modern Ubuntus place this command
|
||||
else if test -f /usr/lib/command-not-found
|
||||
function __fish_command_not_found_handler --on-event fish_command_not_found
|
||||
/usr/lib/command-not-found -- $argv[1]
|
||||
end
|
||||
# Check for NixOS handler
|
||||
# Check for NixOS handler
|
||||
else if test -f /run/current-system/sw/bin/command-not-found
|
||||
function __fish_command_not_found_handler --on-event fish_command_not_found
|
||||
/run/current-system/sw/bin/command-not-found $argv[1]
|
||||
end
|
||||
# Ubuntu Feisty places this command in the regular path instead
|
||||
# Ubuntu Feisty places this command in the regular path instead
|
||||
else if type -q -p command-not-found
|
||||
function __fish_command_not_found_handler --on-event fish_command_not_found
|
||||
command-not-found -- $argv[1]
|
||||
end
|
||||
# pkgfile is an optional, but official, package on Arch Linux
|
||||
# it ships with example handlers for bash and zsh, so we'll follow that format
|
||||
# pkgfile is an optional, but official, package on Arch Linux
|
||||
# it ships with example handlers for bash and zsh, so we'll follow that format
|
||||
else if type -p -q pkgfile
|
||||
function __fish_command_not_found_handler --on-event fish_command_not_found
|
||||
set -l __packages (pkgfile --binaries --verbose -- $argv[1] ^/dev/null)
|
||||
|
@ -223,14 +213,14 @@ function __fish_config_interactive -d "Initializations that should be performed
|
|||
__fish_default_command_not_found_handler $argv[1]
|
||||
end
|
||||
end
|
||||
# Use standard fish command not found handler otherwise
|
||||
# Use standard fish command not found handler otherwise
|
||||
else
|
||||
function __fish_command_not_found_handler --on-event fish_command_not_found
|
||||
__fish_default_command_not_found_handler $argv[1]
|
||||
end
|
||||
end
|
||||
__fish_command_not_found_handler $argv
|
||||
end
|
||||
|
||||
if test $TERM = "linux" # A linux in-kernel VT with 8 colors and 256/512 glyphs
|
||||
# In a VT we have
|
||||
# black (invisible)
|
||||
|
|
Loading…
Reference in New Issue
Block a user