mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-13 13:39:02 +00:00
Check validity of fish_key_bindings
This potentially leads to an unusable session (when fish_key_bindings is set in config.fish to a value without corresponding function), so we should take care.
This commit is contained in:
parent
6594c061be
commit
60317190bd
1 changed files with 22 additions and 6 deletions
|
@ -158,25 +158,41 @@ function __fish_config_interactive -d "Initializations that should be performed
|
||||||
# do nothing if the key bindings didn't actually change
|
# do nothing if the key bindings didn't actually change
|
||||||
# This could be because the variable was set to the existing value
|
# This could be because the variable was set to the existing value
|
||||||
# or because it was a local variable
|
# or because it was a local variable
|
||||||
if test "$fish_key_bindings" = "$__fish_active_key_bindings"
|
# If fish_key_bindings is empty on the first run, we still need to set the defaults
|
||||||
|
if test "$fish_key_bindings" = "$__fish_active_key_bindings" -a -n "$fish_key_bindings"
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
# Check if fish_key_bindings is a valid function
|
||||||
|
# If not, either keep the previous bindings (if any) or revert to default
|
||||||
|
# Also print an error so the user knows
|
||||||
|
if not functions -q "$fish_key_bindings"
|
||||||
|
echo "There is no fish_key_bindings function called: '$fish_key_bindings'" >&2
|
||||||
|
if set -q __fish_active_key_bindings
|
||||||
|
echo "Keeping $__fish_active_key_bindings" >&2
|
||||||
|
return 1
|
||||||
|
else
|
||||||
|
echo "Reverting to default bindings" >&2
|
||||||
|
set fish_key_bindings fish_default_key_bindings
|
||||||
|
# Return because we are called again
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
end
|
||||||
set -g __fish_active_key_bindings "$fish_key_bindings"
|
set -g __fish_active_key_bindings "$fish_key_bindings"
|
||||||
set -g fish_bind_mode default
|
set -g fish_bind_mode default
|
||||||
if test "$fish_key_bindings" = fish_default_key_bindings
|
if test "$fish_key_bindings" = fish_default_key_bindings
|
||||||
fish_default_key_bindings
|
# Redirect stderr per #1155
|
||||||
|
fish_default_key_bindings ^/dev/null
|
||||||
else
|
else
|
||||||
eval $fish_key_bindings ^/dev/null
|
eval $fish_key_bindings ^/dev/null
|
||||||
end
|
end
|
||||||
# Load user key bindings if they are defined
|
# Load user key bindings if they are defined
|
||||||
if functions --query fish_user_key_bindings >/dev/null
|
if functions --query fish_user_key_bindings >/dev/null
|
||||||
fish_user_key_bindings
|
fish_user_key_bindings ^/dev/null
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Load key bindings. Redirect stderr per #1155
|
# Load key bindings
|
||||||
set -g __fish_active_key_bindings
|
__fish_reload_key_bindings
|
||||||
__fish_reload_key_bindings ^/dev/null
|
|
||||||
|
|
||||||
# Repaint screen when window changes size
|
# Repaint screen when window changes size
|
||||||
function __fish_winch_handler --on-signal WINCH
|
function __fish_winch_handler --on-signal WINCH
|
||||||
|
|
Loading…
Reference in a new issue