aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/highlight.cpp
diff options
context:
space:
mode:
authorGravatar ridiculousfish <corydoras@ridiculousfish.com>2016-02-08 01:29:23 -0800
committerGravatar ridiculousfish <corydoras@ridiculousfish.com>2016-02-18 17:00:26 -0800
commit1907323afce50498289c0bbaa67ead1250a0535c (patch)
tree5921b03307738c2b754a2b27d87aa53b0a36f00f /src/highlight.cpp
parentc39b94949be30dfbc1c3e271b37ca04cff303b16 (diff)
Additional work on unifying cd autosuggestions with complete
Diffstat (limited to 'src/highlight.cpp')
-rw-r--r--src/highlight.cpp38
1 files changed, 23 insertions, 15 deletions
diff --git a/src/highlight.cpp b/src/highlight.cpp
index 595631b7..0272c1fa 100644
--- a/src/highlight.cpp
+++ b/src/highlight.cpp
@@ -481,7 +481,7 @@ static bool autosuggest_parse_command(const wcstring &buff, wcstring *out_expand
}
/* We have to return an escaped string here */
-bool autosuggest_suggest_special(const wcstring &str, const wcstring &working_directory, completion_t *out_suggestion)
+bool autosuggest_suggest_special(const wcstring &str, const env_vars_snapshot_t &vars, completion_t *out_suggestion)
{
if (str.empty())
return false;
@@ -500,30 +500,32 @@ bool autosuggest_suggest_special(const wcstring &str, const wcstring &working_di
/* We always return true because we recognized the command. This prevents us from falling back to dumber algorithms; for example we won't suggest a non-directory for the cd command. */
result = true;
-#if 0
+#if 1
std::vector<completion_t> comps;
- complete(str, &comps, COMPLETION_REQUEST_AUTOSUGGESTION);
+ complete(str, &comps, COMPLETION_REQUEST_AUTOSUGGESTION, vars);
if (! comps.empty())
{
*out_suggestion = comps.at(0);
- }
-
- // Hackish to make tests pass
- if (!(out_suggestion->flags & COMPLETE_REPLACES_TOKEN))
- {
- out_suggestion->completion.insert(0, str);
- out_suggestion->flags |= COMPLETE_REPLACES_TOKEN;
- wcstring escaped_dir = last_arg_node.get_source(str);
- wchar_t quote = L'\0';
- parse_util_get_parameter_info(escaped_dir, 0, &quote, NULL, NULL);
- if (quote != L'\0') out_suggestion->completion.push_back(quote);
+ // Hackish to make tests pass
+ if (!(out_suggestion->flags & COMPLETE_REPLACES_TOKEN))
+ {
+ out_suggestion->completion.insert(0, str);
+ out_suggestion->flags |= COMPLETE_REPLACES_TOKEN;
+
+ wcstring escaped_dir = last_arg_node.get_source(str);
+ wchar_t quote = L'\0';
+ parse_util_get_parameter_info(escaped_dir, 0, &quote, NULL, NULL);
+
+ out_suggestion->completion = parse_util_escape_string_with_quote(out_suggestion->completion, quote);
+
+ if (quote != L'\0') out_suggestion->completion.push_back(quote);
+ }
}
return result;
#endif
-
/* We can possibly handle this specially */
const wcstring escaped_dir = last_arg_node.get_source(str);
wcstring suggested_path;
@@ -542,6 +544,12 @@ bool autosuggest_suggest_special(const wcstring &str, const wcstring &working_di
/* Big hack to avoid expanding a tilde inside quotes */
path_flags_t path_flags = (quote == L'\0') ? PATH_EXPAND_TILDE : 0;
+ env_var_t working_directory = vars.get(L"PWD");
+ if (working_directory.missing_or_empty())
+ {
+ working_directory = L".";
+ }
+
if (unescaped && is_potential_cd_path(unescaped_dir, working_directory, path_flags, &suggested_path))
{
/* Note: this looks really wrong for strings that have an "unescapable" character in them, e.g. a \t, because parse_util_escape_string_with_quote will insert that character */