completions/cdh: Only shorten ~ if the token starts with one

Works around #4570

Also keep order like it always wanted.

[ci skip]
This commit is contained in:
Fabian Homborg 2020-10-28 18:15:00 +01:00
parent 6aed132224
commit 0259b29a09

View file

@ -11,13 +11,20 @@ function __fish_cdh_args
end end
end end
# Only shorten $HOME to "~" if the token starts with a "~",
# otherwise fish will escape it.
set -l shorten_tilde 0
string match -q '~*' -- (commandline -ct); and set shorten_tilde 1
for dir in $uniq_dirs for dir in $uniq_dirs
set -l home_dir (string match -r "$HOME(/.*|\$)" "$dir") if test $shorten_tilde -eq 1
if set -q home_dir[2] set -l home_dir (string match -r "$HOME(/.*|\$)" "$dir")
set dir "~$home_dir[2]" if set -q home_dir[2]
set dir "~$home_dir[2]"
end
end end
echo $dir echo $dir
end end
end end
complete -c cdh -xa '(__fish_cdh_args)' complete -c cdh -kxa '(__fish_cdh_args)'