aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Fabian Homborg <FHomborg@gmail.com>2015-12-29 15:41:00 +0100
committerGravatar Fabian Homborg <FHomborg@gmail.com>2015-12-30 16:26:54 +0100
commit1a12071a48a4ead52c8749118aef2a1016bdc5e5 (patch)
treefa9a3f36f2475882d354de5517dbe51955c9e9ce
parentb7fb11cb7f8e05fecaf96ee93af285d8778d10c2 (diff)
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.
-rw-r--r--share/config.fish5
-rw-r--r--share/functions/__fish_config_interactive.fish34
2 files changed, 14 insertions, 25 deletions
diff --git a/share/config.fish b/share/config.fish
index f1bb0c0c..b1d404ee 100644
--- a/share/config.fish
+++ b/share/config.fish
@@ -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
diff --git a/share/functions/__fish_config_interactive.fish b/share/functions/__fish_config_interactive.fish
index c9accc6b..0d9ba486 100644
--- a/share/functions/__fish_config_interactive.fish
+++ b/share/functions/__fish_config_interactive.fish
@@ -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)