diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 0d46a7d3a..37b497089 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -76,6 +76,7 @@ Scripting improvements - ``dirs`` always produces an exit status of 0, instead of sometimes returning 1 (:issue:`8211`). - ``cd ""`` no longer crashes fish (:issue:`8147`). - ``set --query`` can now query whether a variable is a pathvar via ``--path`` or ``--unpath`` (:issue:`8494`). +- Tilde characters (``~``) produced by custom completions are no longer escaped when applied to the command line, making it easier to use the output of a recursive ``complete -C`` in completion scripts (:issue:`4570`). Interactive improvements ------------------------ diff --git a/share/completions/cdh.fish b/share/completions/cdh.fish index c06146a32..db9f22799 100644 --- a/share/completions/cdh.fish +++ b/share/completions/cdh.fish @@ -11,17 +11,10 @@ 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 - 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 + set -l home_dir (string match -r "$HOME(/.*|\$)" "$dir") + if set -q home_dir[2] + set dir "~$home_dir[2]" end echo $dir end diff --git a/share/completions/obnam.fish b/share/completions/obnam.fish index ff7822f73..10436957d 100644 --- a/share/completions/obnam.fish +++ b/share/completions/obnam.fish @@ -160,4 +160,4 @@ complete -c obnam --no-files -l no-pure-paramiko -d 'Use openssh if available' complete -c obnam -l ssh-command -d 'Executable to be used instead of "ssh"' complete -c obnam --no-files -l ssh-host-keys-check -a 'no yes ask ssh-config' -d 'ssh host key check' complete -c obnam -l ssh-key -d 'Use FILENAME as the ssh RSA key' -complete -c obnam -l ssh-known-hosts -a '~/.ssh/known_hosts' -d 'FILENAME of the known_hosts file' +complete -c obnam -l ssh-known-hosts -a '\\~/.ssh/known_hosts' -d 'FILENAME of the known_hosts file' diff --git a/src/builtins/complete.cpp b/src/builtins/complete.cpp index abbfd347b..5d527ea72 100644 --- a/src/builtins/complete.cpp +++ b/src/builtins/complete.cpp @@ -418,6 +418,9 @@ maybe_t builtin_complete(parser_t &parser, io_streams_t &streams, const wch } } else { int flags = COMPLETE_AUTO_SPACE; + // HACK: Don't escape tildes because at the beginning of a token they probably mean + // $HOME, for example as produced by a recursive call to "complete -C". + flags |= COMPLETE_DONT_ESCAPE_TILDES; if (preserve_order) { flags |= COMPLETE_DONT_SORT; }