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:
Fabian Homborg 2015-12-29 15:41:00 +01:00
parent b7fb11cb7f
commit 1a12071a48
2 changed files with 14 additions and 25 deletions

View file

@ -19,10 +19,9 @@ end
# #
# Hook up the default as the principal command_not_found handler # Hook up the default as the principal command_not_found handler
# for starting up since finding and executing a real one is not cheap # in case we are not interactive
# This will be erased in __fish_command_not_found_setup once we're 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 __fish_default_command_not_found_handler $argv
end end

View file

@ -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 __update_vte_cwd # Run once because we might have already inherited a PWD from an old tab
end end
# Remove the startup command_not_found handler since we're done with it ### Command-not-found handlers
functions -e __fish_startup_command_not_found_handler # This can be overridden by defining a new __fish_command_not_found_handler function
if not type -q __fish_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
# First check if we are on OpenSUSE since SUSE's handler has no options # 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 # and expects first argument to be a command and second database
# also check if there is command-not-found command. # 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 function __fish_command_not_found_handler --on-event fish_command_not_found
/usr/bin/command-not-found $argv[1] /usr/bin/command-not-found $argv[1]
end end
# Check for Fedora's handler # Check for Fedora's handler
else if test -f /usr/libexec/pk-command-not-found else if test -f /usr/libexec/pk-command-not-found
function __fish_command_not_found_handler --on-event fish_command_not_found function __fish_command_not_found_handler --on-event fish_command_not_found
/usr/libexec/pk-command-not-found $argv[1] /usr/libexec/pk-command-not-found $argv[1]
end 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 else if test -f /usr/lib/command-not-found
function __fish_command_not_found_handler --on-event fish_command_not_found function __fish_command_not_found_handler --on-event fish_command_not_found
/usr/lib/command-not-found -- $argv[1] /usr/lib/command-not-found -- $argv[1]
end end
# Check for NixOS handler # Check for NixOS handler
else if test -f /run/current-system/sw/bin/command-not-found else if test -f /run/current-system/sw/bin/command-not-found
function __fish_command_not_found_handler --on-event fish_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] /run/current-system/sw/bin/command-not-found $argv[1]
end 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 else if type -q -p command-not-found
function __fish_command_not_found_handler --on-event fish_command_not_found function __fish_command_not_found_handler --on-event fish_command_not_found
command-not-found -- $argv[1] command-not-found -- $argv[1]
end end
# pkgfile is an optional, but official, package on Arch Linux # 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 # it ships with example handlers for bash and zsh, so we'll follow that format
else if type -p -q pkgfile else if type -p -q pkgfile
function __fish_command_not_found_handler --on-event fish_command_not_found function __fish_command_not_found_handler --on-event fish_command_not_found
set -l __packages (pkgfile --binaries --verbose -- $argv[1] ^/dev/null) 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] __fish_default_command_not_found_handler $argv[1]
end end
end end
# Use standard fish command not found handler otherwise # Use standard fish command not found handler otherwise
else else
function __fish_command_not_found_handler --on-event fish_command_not_found function __fish_command_not_found_handler --on-event fish_command_not_found
__fish_default_command_not_found_handler $argv[1] __fish_default_command_not_found_handler $argv[1]
end end
end end
__fish_command_not_found_handler $argv
end end
if test $TERM = "linux" # A linux in-kernel VT with 8 colors and 256/512 glyphs if test $TERM = "linux" # A linux in-kernel VT with 8 colors and 256/512 glyphs
# In a VT we have # In a VT we have
# black (invisible) # black (invisible)