-
Notifications
You must be signed in to change notification settings - Fork 403
Closed
Description
Describe the bug
CDPATH entries may be empty, which according to the bash documentation is equivalent to .; however it is slightly different in practice because . will echo the directory name while the empty string will not.
When CDPATH includes an empty string (e.g., CDPATH=:~/cdpath) the completion includes directories under the root directory /.
This appears to be a working one-line fix:
diff --git a/completions/cd b/completions/cd
index 8de903a6..51692079 100644
--- a/completions/cd
+++ b/completions/cd
@@ -38,6 +38,7 @@ _comp_cmd_cd__compgen_cdpath()
local paths dirs _d
_comp_split -F : paths "$CDPATH"
for _p in "${paths[@]}"; do
+ _p="${_p:-.}"
# create an array of matched subdirs
_comp_compgen -v dirs -c "$_p/$cur" -- -d
for _d in "${dirs[@]}"; do
To reproduce
$ env -i bwrap --ro-bind / / --dev /dev --ro-bind /etc/skel $HOME bash
[joe@doughboy joe]$ ls
[joe@doughboy joe]$ CDPATH=:$HOME
[joe@doughboy joe]$ cd s[TAB][TAB]
sbin/ srv/ sys/
This is basically a default empty home directory with CDPATH set to :/home/joe.
Expected behavior
The current home directory is empty so there should be no completions.
Versions (please complete the following information)
- Operating system name/distribution and version: Fedora 43
- bash version,
echo "$BASH_VERSION": 5.3.0(1)-release (x86_64-redhat-linux-gnu) - bash-completion version,
(IFS=.; echo "${BASH_COMPLETION_VERSINFO[*]}"): 2 16 0 (also reproduced at commit e8a3d33)
Additional context
Debug trace
Metadata
Metadata
Assignees
Labels
No labels