From 2f3123e1757f495afc799f0c734283d4513db0f8 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Mon, 31 Aug 2015 18:39:15 +0200 Subject: [PATCH] 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 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 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 --- share/config.fish | 5 +++-- share/functions/__fish_config_interactive.fish | 12 +++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/share/config.fish b/share/config.fish index 75d8cb478..f1bb0c0c4 100644 --- a/share/config.fish +++ b/share/config.fish @@ -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 diff --git a/share/functions/__fish_config_interactive.fish b/share/functions/__fish_config_interactive.fish index fa1e140db..e9e2d9122 100644 --- a/share/functions/__fish_config_interactive.fish +++ b/share/functions/__fish_config_interactive.fish @@ -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.