From 859edc9c2cd0275f86adc513994533d2370ce948 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Fri, 23 Jul 2021 17:21:12 +0200 Subject: [PATCH] Implicitly use $PWD in $CDPATH in completions and highlighting We already do for the actual cd-ing itself. Missed in #4484. Fixes #8161. --- src/expand.cpp | 6 +++--- src/highlight.cpp | 2 ++ tests/checks/cd.fish | 5 +++++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/expand.cpp b/src/expand.cpp index 17bcad32f..b654d9fd0 100644 --- a/src/expand.cpp +++ b/src/expand.cpp @@ -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)); diff --git a/src/highlight.cpp b/src/highlight.cpp index e83c7908d..1650d82c9 100644 --- a/src/highlight.cpp +++ b/src/highlight.cpp @@ -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"."; diff --git a/tests/checks/cd.fish b/tests/checks/cd.fish index a993b6edb..6ab7f2598 100644 --- a/tests/checks/cd.fish +++ b/tests/checks/cd.fish @@ -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