mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-05-21 03:21:16 -03:00
Migrate abbrs from =-separated to space-separated
We silently upgrade existing abbreviations and change the separator when saving. This does not yet warn when the user is using the old syntax. Resolves #2051
This commit is contained in:
committed by
Kurtis Rader
parent
fbd53f2da1
commit
0e8a8a7c80
@@ -72,8 +72,12 @@ function abbr --description "Manage abbreviations"
|
||||
|
||||
switch $mode
|
||||
case 'add'
|
||||
# Convert from old "key=value" to new "key value" syntax
|
||||
if string match -qr '^[^ ]+=' -- $mode_arg
|
||||
set mode_arg (string replace "=" " " -- $mode_arg)
|
||||
end
|
||||
|
||||
# Bail out early if the exact abbr is already in
|
||||
# This depends on the separator staying the same, but that's the common case (config.fish)
|
||||
contains -- $mode_arg $fish_user_abbreviations; and return 0
|
||||
set -l key
|
||||
set -l value
|
||||
@@ -141,12 +145,8 @@ function __fish_abbr_get_by_key
|
||||
# Going through all entries is still quicker than calling `seq`
|
||||
set -l keys
|
||||
for kv in $fish_user_abbreviations
|
||||
if string match -qr '^[^ ]+=' -- $kv
|
||||
# No need for bounds-checking because we already matched before
|
||||
set keys $keys (string split "=" -m 1 -- $kv)[1]
|
||||
else if string match -qr '^[^ ]+ .*' -- $kv
|
||||
set keys $keys (string split " " -m 1 -- $kv)[1]
|
||||
end
|
||||
# If this does not match, we have screwed up before and the error should be reported
|
||||
set keys $keys (string split " " -m 1 -- $kv)[1]
|
||||
end
|
||||
if set -l idx (contains -i -- $argv[1] $keys)
|
||||
echo $idx
|
||||
@@ -156,11 +156,6 @@ function __fish_abbr_get_by_key
|
||||
end
|
||||
|
||||
function __fish_abbr_split -a input
|
||||
if string match -qr '^[^ ]+=' -- $input
|
||||
string split "=" -m 1 -- $input
|
||||
else if string match -qr '^[^ ]+ .*' -- $input
|
||||
string split " " -m 1 -- $input
|
||||
else
|
||||
echo $input
|
||||
end
|
||||
# Because we always save space-separated, we can be certain that this will match
|
||||
string split " " -m 1 -- $input
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user