Make overriding cnf-handler work

See #1925: This allows users to disable the cnf-logic which can be quite
slow on small hardware (like a raspberry pi).

Squashed commit of the following:

commit 742a59e30d8db24b6bb5067d4204d4b5cc01c1c3
Author: Fabian Homborg <FHomborg@gmail.com>
Date:   Sun Aug 30 18:23:41 2015 +0200

    Erase startup cnf-handler early

    Simplifies the code a bit - in particular it removes the special-casing
    from the startup handler.

commit 638a97e7f31f302b65e044c93c638c03a69e31f5
Author: Fabian Homborg <FHomborg@gmail.com>
Date:   Mon Aug 24 20:14:46 2015 +0200

    Make overriding cnf-handler work

    Do this by renaming the __fish_command_not_found_handler used during
    startup to __fish_startup_command_not_found_handler. That allows us to
    check if __fish_command_not_found_handler has been defined and skip the
    setup of the normal one.

    Now disabling cnf-handling can be done via defining an empty
    __fish_command_not_found_handler in config.fish
This commit is contained in:
Fabian Homborg 2015-08-31 18:39:15 +02:00
parent 17c756971a
commit 2f3123e175
2 changed files with 10 additions and 7 deletions

View file

@ -19,9 +19,10 @@ end
#
# Hook up the default as the principal command_not_found handler
# This is likely to be overwritten in __fish_config_interactive
# 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
#
function __fish_command_not_found_handler --on-event fish_command_not_found
function __fish_startup_command_not_found_handler --on-event fish_command_not_found
__fish_default_command_not_found_handler $argv
end

View file

@ -196,17 +196,19 @@ function __fish_config_interactive -d "Initializations that should be performed
end
end
# The first time a command is not found, look for command-not-found
# This is not cheap so we try to avoid doing it during startup
# config.fish already installed a handler for noninteractive command-not-found,
# so delete it here since we are now interactive
functions -e __fish_command_not_found_handler
# 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
# 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.