Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion bash_completion
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,16 @@ if ((BASH_VERSINFO[0] > 5 || BASH_VERSINFO[0] == 5 && BASH_VERSINFO[1] >= 3)); t
[[ $_dir ]] && command cd -- "$_original_pwd"

((${#_upvars[@]})) && _comp_unlocal "${_upvars[@]}"
((${#_result[@]})) || return

# workaround for bash-4.2 nounset
((${#_result[@]})) || {
if [[ $_append ]]; then
eval -- "$_var+=()"
else
eval -- "$_var=()"
fi
return
}

if [[ $_prefix ]]; then
local _i
Expand Down
19 changes: 10 additions & 9 deletions completions/cd
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ _comp_cmd_cd__compgen_cdpath()
_comp_split -F : paths "$CDPATH"
for _p in "${paths[@]}"; do
# create an array of matched subdirs
_comp_compgen -v dirs -c "$_p/$cur" -- -d
for _d in "${dirs[@]}"; do
if [[ ($_mark_symdirs && -L $_d || $_mark_dirs && ! -L $_d) && ! -d ${_d#"$_p/"} ]]; then
_d+="/"
fi
_cdpaths+=("${_d#"$_p/"}")
done
_comp_compgen -v dirs -c "$_p/$cur" -- -d &&
for _d in "${dirs[@]}"; do
if [[ ($_mark_symdirs && -L $_d || $_mark_dirs && ! -L $_d) && ! -d ${_d#"$_p/"} ]]; then
_d+="/"
fi
_cdpaths+=("${_d#"$_p/"}")
done
done
_comp_unlocal paths dirs

Expand All @@ -56,7 +56,8 @@ _comp_cmd_cd__compgen_cdpath()
fi
fi

_comp_compgen_set "${_cdpaths[@]}"
((${#_cdpaths[@]})) &&
_comp_compgen_set "${_cdpaths[@]}"
}

_comp_cmd_cd()
Expand All @@ -72,7 +73,7 @@ _comp_cmd_cd()

compopt -o filenames
_comp_cmd_cd__compgen_cdable_vars
_comp_cmd_cd__compgen_cdpath
_comp_compgen -ai cd cdpath
_comp_compgen -a filedir -d
}
complete -F _comp_cmd_cd -o nospace cd pushd
9 changes: 9 additions & 0 deletions test/t/test_cd.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,12 @@ def test_cdable_vars(self, bash):
bash_env.write_variable("foo6", "shared/default/bar")
completion = assert_complete(bash, "cd f")
assert completion == ["foo1", "foo2"]

def test_cdable_vars_2(self, bash):
with bash_env_saved(bash) as bash_env:
bash_env.write_variable("CDPATH", "nonexistent")
bash_env.shopt("cdable_vars", True)
bash_env.write_variable("foo1", "shared")
bash_env.write_variable("foo2", "shared/default")
completion = assert_complete(bash, "cd f")
assert completion == ["foo1", "foo2"]
Loading