bash-completion
bash-completion copied to clipboard
Completing a relative path with a space and softlinks inside, turns it absolute (which breaks creating relative softlinks)
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
cd /tmp; mkdir TEST; cd TESTmkdir -p 'aaa/c c' 'aaa/xxx' 'aaa/yyy' bbbcd 'aaa/c c/'ln -s ../xxx; ln -s ../yyycd ../../bbbln -s ../aaa/cand press ⟨TAB⟩ once, to get../aaa/c\ c/.- 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)
- [x] Operating system name/distribution and version: Linux Mint 21.3 Virginia
- [x] bash version,
echo "$BASH_VERSION": 5.1.16(1)-release - [x] bash-completion version,
(IFS=.; echo "${BASH_COMPLETION_VERSINFO[*]}"): 2.11
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
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
Closing due to lack of further info regarding the reproducer. Let's reopen if we receive that later.