scop / bash-completion

Programmable completion functions for bash
GNU General Public License v2.0
2.8k stars 376 forks source link

Completing a relative path with a space and softlinks inside, turns it absolute (which breaks creating relative softlinks) #1223

Open navid-zamani opened 1 week ago

navid-zamani commented 1 week ago

Describe the bug

Double-completing a relative path with a space in the name and softlinks inside it, results in it being turned into an absolute path.
This breaks attempts at passing relative paths to commands (like is common with ln).

To reproduce

  1. cd /tmp; mkdir TEST; cd TEST
  2. mkdir -p 'aaa/c c' 'aaa/xxx' 'aaa/yyy' bbb
  3. cd 'aaa/c c/'
  4. ln -s ../xxx; ln -s ../yyy
  5. cd ../../bbb
  6. ln -s ../aaa/c and press ⟨TAB⟩ once, to get ../aaa/c\ c/.
  7. Press ⟨TAB⟩ again. And get /tmp/TEST/aaa/c\ c/.

Expected behavior

One should get ../aaa/c\ c/ with xxx/ yyy/ as suggestions.

Versions (please complete the following information)

Additional context

It doesn’t happen, if there are no softlinks inside 'c c', of if there is no space in the name of that directory.
But a very similar problem happens for tilde (~). Which needs fixing for the same reason.
Also, I haven’t checked but suspect that if it transforms it like realpath does, turning any softlink component into the real path. (Which also breaks creating softlinks that use these other softlinks to work in several different environments.)

In my case I have several computers all syncing the same directories, but into a different base path since software expects those exact locations. Relative softlinks and softlinks that use other softlinks in their paths are the only way to get all paths to work on all systems. Especially since one of them is a Termux install on Android, where things like bind mounts don’t work, some paths (like pictures) are forcibly somewhere else, and $HOME is very different.

Debug trace

trace.log

akinomyoga commented 1 week ago

I cannot reproduce the problem. I also tried the combination of the reported versions, Bash-5.1.16 and bash-completion-2.11, but the problem doesn't arise. (edit: I now also tried it in Linux Mint 21.2 because I had a virtual machine, but the problem still doesn't reproduce). The provided trace.log doesn't seem to contain any /tmp/TEST/aaa/c c except the very last line (which is printed by Bash).

What are the result of the following commands (before and after the problem is triggered)?

$ complete -p ln
$ declare -p toks
$ shopt -p localvar_inherit

What are the results of the following commands?

$ echo "[$-]"
$ echo "$BASH_OPTS"
$ bind -v