From 0259b29a098ef47478d53afd2e902d26c2ec1784 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Wed, 28 Oct 2020 18:15:00 +0100 Subject: [PATCH] completions/cdh: Only shorten ~ if the token starts with one Works around #4570 Also keep order like it always wanted. [ci skip] --- share/completions/cdh.fish | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/share/completions/cdh.fish b/share/completions/cdh.fish index f54e2a2d1..c06146a32 100644 --- a/share/completions/cdh.fish +++ b/share/completions/cdh.fish @@ -11,13 +11,20 @@ function __fish_cdh_args 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 - set -l home_dir (string match -r "$HOME(/.*|\$)" "$dir") - if set -q home_dir[2] - set dir "~$home_dir[2]" + if test $shorten_tilde -eq 1 + set -l home_dir (string match -r "$HOME(/.*|\$)" "$dir") + if set -q home_dir[2] + set dir "~$home_dir[2]" + end end echo $dir end end -complete -c cdh -xa '(__fish_cdh_args)' +complete -c cdh -kxa '(__fish_cdh_args)'