Implicitly use $PWD in $CDPATH in completions and highlighting

We already do for the actual cd-ing itself.

Missed in #4484.

Fixes #8161.
This commit is contained in:
Fabian Homborg 2021-07-23 17:21:12 +02:00
parent c35ffc58fc
commit 859edc9c2c
3 changed files with 10 additions and 3 deletions

View file

@ -1079,9 +1079,9 @@ expand_result_t expander_t::stage_wildcards(wcstring path_to_expand, completion_
if (auto paths_var = ctx.vars.get(for_cd ? L"CDPATH" : L"PATH")) {
paths = paths_var->as_list();
}
if (paths.empty()) {
paths.emplace_back(for_cd ? L"." : L"");
}
// The current directory is always valid.
paths.emplace_back(for_cd ? L"." : L"");
for (const wcstring &next_path : paths) {
effective_working_dirs.push_back(
path_apply_working_directory(next_path, working_dir));

View file

@ -322,6 +322,8 @@ static bool is_potential_cd_path(const wcstring &path, const wcstring &working_d
auto cdpath = ctx.vars.get(L"CDPATH");
wcstring_list_t pathsv =
cdpath.missing_or_empty() ? wcstring_list_t{L"."} : cdpath->as_list();
// The current $PWD is always valid.
pathsv.push_back(L".");
for (auto next_path : pathsv) {
if (next_path.empty()) next_path = L".";

View file

@ -163,6 +163,11 @@ mkdir -p cdpath-dir/nonexistent
mkdir -p cdpath-dir/file
set CDPATH $PWD/cdpath-dir $old_cdpath
# See that the completions also check the current directory
complete -C'cd ' | string match -q cdpath-dir/
and echo cdpath-dir is in
# CHECK: cdpath-dir is in
# A different directory with the same name that is first in $CDPATH works.
cd bad-perms
cd $old_path