You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
tilde characters in scripted tab completions are escaped (sometimes) #4570
msteed@bones:~> fish --version
fish, version 2.7.0
msteed@bones:~>echo$version
2.7.0
msteed@bones:~> uname -a
Linux bones 4.13.12-1-ARCH #1 SMP PREEMPT Wed Nov 8 11:54:06 CET 2017 x86_64 GNU/Linux
msteed@bones:~>echo$TERM
tmux-256color
msteed@bones:~>
The problem:
msteed@bones:~> sh -c 'env HOME=$(mktemp -d) fish'
Welcome to fish, the friendly interactive shell
msteed@bones /h/msteed>cd
msteed@bones ~> mkdir -p a/b
msteed@bones ~>cd a/b
msteed@bones ~/a/b>cd
msteed@bones ~> cdh a<TAB>
When I hit Tab, fish supplies this completion:
msteed@bones ~> cdh \~/a/b
If I accept that, fish (correctly) complains:
cd: The directory “~/a/b” does not exist
If I hit Tab with an empty directory name, i.e., cdh <TAB>, fish lists the completions with the ~ characters escaped, but selecting a completion un-escapes the string so the command line is formatted correctly.
The problem is, basically, that fish always assumes scripted completions shouldn't contain anything that expands, so if a completion prints $VAR that should be escaped to \$VAR, or, as in this case, if it prints ~/something that it should escape the ~. There's an exception for if the current token already starts with a ~, but I'm not sure why and if that is intentional.
That seems to be the right thing in most circumstances, and I don't think changing the default is workable (e.g. is there a case where git expects an argument starting with ~?).
Or it might be possible to just not escape ~?
Or maybe expand the ~ to the value of $HOME?
It's possible that this could be done with an option to complete - complete --unescaped that would then have to be used in the cdh completions (and everywhere else where it's applicable).
But really, this requires looking at what completions commonly need and figuring out the best way to satisfy that, while not breaking the existing completion scripts.
In the meantime, I'm just going to remove the ~ shortening from the cdh completions unless the current token starts with ~. It's only cosmetic anyway, and in that case it's preferable to have something that works.
changed the title [-]tilde characters in cdh tab completions are escaped (sometimes)[/-][+]tilde characters in scripted tab completions are escaped (sometimes)[/+]on Jul 14, 2021
function _complete
if ! commandline-Pset-l token (commandline-t)
if string match -q -- "\~*"$tokencommandline-rt (string replace \\""$token)
returnendendcommandline-fcompleteendbind\t _complete
Now use tilde in your completions, and when fish completes leading \~, just press Tab again and it be replaced with a working one.
I ran into this issue with a custom completion that uses __fish_complete_directories. I can reliably reproduce it with unzip whose completion file uses both __fish_complete_directories and __fish_complete_suffix. For example, if I have a file in my home directory called archive.zip and I run this:
unzip ~/zip<TAB>
I would expect it to complete to unzip ~/archive.zip but it actually completes to unzip \~/archive.zip. Similarly, this...
unzip -d ~/Dw<TAB>
...completes to unzip -d \~/Downloads/.
Completing something that doesn't require replacement (e.g., unzip ~/arc<TAB>) works fine.
It's possible that this could be done with an option to complete - complete --unescaped that would then have to be used in the cdh completions (and everywhere else where it's applicable).
Activity
yig commentedon Oct 28, 2020
I just ran into this. Does anyone have any pointers for how I might fix this (and make a pull request)?
faho commentedon Oct 28, 2020
@yig: This is a bit of a tough one.
The problem is, basically, that fish always assumes scripted completions shouldn't contain anything that expands, so if a completion prints
$VARthat should be escaped to\$VAR, or, as in this case, if it prints~/somethingthat it should escape the~. There's an exception for if the current token already starts with a~, but I'm not sure why and if that is intentional.That seems to be the right thing in most circumstances, and I don't think changing the default is workable (e.g. is there a case where git expects an argument starting with
~?).Or it might be possible to just not escape
~?Or maybe expand the
~to the value of $HOME?It's possible that this could be done with an option to
complete-complete --unescapedthat would then have to be used in thecdhcompletions (and everywhere else where it's applicable).But really, this requires looking at what completions commonly need and figuring out the best way to satisfy that, while not breaking the existing completion scripts.
In the meantime, I'm just going to remove the
~shortening from the cdh completions unless the current token starts with~. It's only cosmetic anyway, and in that case it's preferable to have something that works.completions/cdh: Only shorten ~ if the token starts with one
[-]tilde characters in cdh tab completions are escaped (sometimes)[/-][+]tilde characters in scripted tab completions are escaped (sometimes)[/+]kidonng commentedon Oct 6, 2021
Here is a little workaround I come up with:
Now use tilde in your completions, and when fish completes leading
\~, just pressTabagain and it be replaced with a working one.cstyles commentedon Nov 13, 2021
I ran into this issue with a custom completion that uses
__fish_complete_directories. I can reliably reproduce it withunzipwhose completion file uses both__fish_complete_directoriesand__fish_complete_suffix. For example, if I have a file in my home directory calledarchive.zipand I run this:I would expect it to complete to
unzip ~/archive.zipbut it actually completes tounzip \~/archive.zip. Similarly, this......completes to
unzip -d \~/Downloads/.Completing something that doesn't require replacement (e.g.,
unzip ~/arc<TAB>) works fine.I opened #8441 to do this.