mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-26 04:43:10 +00:00
harden abbr
against undef vars
This is only needed if we make undefined vars an error as proposed in issue #4163 but it's a good idea anyway.
This commit is contained in:
parent
763063e741
commit
0ec9acf0f0
2 changed files with 8 additions and 2 deletions
|
@ -96,8 +96,10 @@ function abbr --description "Manage abbreviations"
|
||||||
end
|
end
|
||||||
|
|
||||||
# Bail out early if the exact abbr is already in
|
# Bail out early if the exact abbr is already in
|
||||||
contains -- "$mode_arg" $fish_user_abbreviations
|
set -q fish_user_abbreviations
|
||||||
|
and contains -- "$mode_arg" $fish_user_abbreviations
|
||||||
and return 0
|
and return 0
|
||||||
|
|
||||||
set -l key $mode_arg[1]
|
set -l key $mode_arg[1]
|
||||||
set -e mode_arg[1]
|
set -e mode_arg[1]
|
||||||
set -l value "$mode_arg"
|
set -l value "$mode_arg"
|
||||||
|
@ -186,6 +188,10 @@ function __fish_abbr_get_by_key
|
||||||
echo "__fish_abbr_get_by_key: expected one argument, got none" >&2
|
echo "__fish_abbr_get_by_key: expected one argument, got none" >&2
|
||||||
return 2
|
return 2
|
||||||
end
|
end
|
||||||
|
|
||||||
|
set -q fish_user_abbreviations
|
||||||
|
or return 1
|
||||||
|
|
||||||
# Going through all entries is still quicker than calling `seq`
|
# Going through all entries is still quicker than calling `seq`
|
||||||
set -l keys
|
set -l keys
|
||||||
for kv in $fish_user_abbreviations
|
for kv in $fish_user_abbreviations
|
||||||
|
|
|
@ -11,7 +11,7 @@ abbr __abbr1 alpha beta gamma
|
||||||
abbr | grep __abbr1
|
abbr | grep __abbr1
|
||||||
|
|
||||||
# Replacing
|
# Replacing
|
||||||
abbr __abbr1 delta
|
abbr __abbr1 delta
|
||||||
abbr | grep __abbr1
|
abbr | grep __abbr1
|
||||||
|
|
||||||
# -s and --show tests
|
# -s and --show tests
|
||||||
|
|
Loading…
Reference in a new issue