From 99b51ce6eadcc93027c6edf9a0def836ac050870 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sun, 6 May 2012 14:53:19 -0700 Subject: [PATCH] Fix to better support CDPATH --- builtin_set.cpp | 4 +--- complete.cpp | 6 +++++- env.cpp | 3 ++- path.cpp | 9 ++++++++- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/builtin_set.cpp b/builtin_set.cpp index a02bc94f1..e2b3c2a27 100644 --- a/builtin_set.cpp +++ b/builtin_set.cpp @@ -49,9 +49,7 @@ extern wcstring stdout_buffer, stderr_buffer; */ static int is_path_variable( const wchar_t *env ) { - return contains( env, - L"PATH" - ); + return contains(env, L"PATH", L"CDPATH" ); } /** diff --git a/complete.cpp b/complete.cpp index fd51b2261..b3218a3e7 100644 --- a/complete.cpp +++ b/complete.cpp @@ -1009,8 +1009,12 @@ void completer_t::complete_cmd( const wcstring &str, bool use_function, bool use wchar_t *state; std::vector possible_comp; - wchar_t *cdpath_cpy = wcsdup(L"."); + env_var_t cdpath = env_get_string(L"CDPATH"); + if (cdpath.missing_or_empty()) + cdpath = L"."; + wchar_t *cdpath_cpy = wcsdup(cdpath.c_str()); + const bool wants_description = (type == COMPLETE_DEFAULT); if( (wcschr( cmd, L'/') != 0) || (cmd[0] == L'~' ) ) diff --git a/env.cpp b/env.cpp index 813df8601..c6373cdf2 100644 --- a/env.cpp +++ b/env.cpp @@ -1525,4 +1525,5 @@ const wchar_t *env_vars::get(const wchar_t *key) const return (iter == vars.end() ? NULL : iter->second.c_str()); } -const wchar_t * const env_vars::highlighting_keys[] = {L"PATH", L"HIGHLIGHT_DELAY", L"fish_function_path", NULL}; +const wchar_t * const env_vars::highlighting_keys[] = {L"PATH", L"CDPATH", L"HIGHLIGHT_DELAY", L"fish_function_path", NULL}; + diff --git a/path.cpp b/path.cpp index 4003644c6..05b20c139 100644 --- a/path.cpp +++ b/path.cpp @@ -377,7 +377,7 @@ wchar_t *path_allocate_cdpath( const wchar_t *dir, const wchar_t *wd ) // Respect CDPATH env_var_t path = env_get_string(L"CDPATH"); - if (path.missing_or_empty()) path = L"."; + if (path.missing_or_empty()) path = L"."; //We'll change this to the wd if we have one path_cpy = wcsdup( path.c_str() ); @@ -385,6 +385,13 @@ wchar_t *path_allocate_cdpath( const wchar_t *dir, const wchar_t *wd ) nxt_path != NULL; nxt_path = wcstok( 0, ARRAY_SEP_STR, &state) ) { + + if (! wcscmp(nxt_path, L".") && wd != NULL) { + // nxt_path is just '.', and we have a working directory, so use the wd instead + // TODO: if nxt_path starts with ./ we need to replace the . with the wd + nxt_path = wd; + } + wchar_t *expanded_path = expand_tilde_compat( wcsdup(nxt_path) ); // debug( 2, L"woot %ls\n", expanded_path );