aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/complete.cpp5
-rw-r--r--src/expand.h5
-rw-r--r--src/wildcard.cpp6
3 files changed, 11 insertions, 5 deletions
diff --git a/src/complete.cpp b/src/complete.cpp
index ae9d2ef3..3d79de04 100644
--- a/src/complete.cpp
+++ b/src/complete.cpp
@@ -1147,11 +1147,12 @@ void completer_t::complete_cmd(const wcstring &str_cmd, bool use_function, bool
nxt_completion.append(str_cmd);
size_t prev_count = this->completions.size();
+ expand_flags_t expand_flags = EXPAND_FOR_COMPLETIONS | EXECUTABLES_ONLY | EXPAND_NO_FUZZY_DIRECTORIES | this->expand_flags();
if (expand_string(nxt_completion,
&this->completions,
- EXPAND_FOR_COMPLETIONS | EXECUTABLES_ONLY | this->expand_flags(), NULL) != EXPAND_ERROR)
+ expand_flags, NULL) != EXPAND_ERROR)
{
- /* For all new completions, if COMPLETE_NO_CASE is set, then use only the last path component */
+ /* For all new completions, if COMPLETE_REPLACES_TOKEN is set, then use only the last path component */
for (size_t i=prev_count; i< this->completions.size(); i++)
{
completion_t &c = this->completions.at(i);
diff --git a/src/expand.h b/src/expand.h
index a6b287f4..b07186e4 100644
--- a/src/expand.h
+++ b/src/expand.h
@@ -56,7 +56,10 @@ enum
EXPAND_SKIP_HOME_DIRECTORIES = 1 << 8,
/** Allow fuzzy matching */
- EXPAND_FUZZY_MATCH = 1 << 9
+ EXPAND_FUZZY_MATCH = 1 << 9,
+
+ /** Disallow directory abbreviations like /u/l/b for /usr/local/bin. Only applicable if EXPAND_FUZZY_MATCH is set. */
+ EXPAND_NO_FUZZY_DIRECTORIES = 1 << 10
};
typedef int expand_flags_t;
diff --git a/src/wildcard.cpp b/src/wildcard.cpp
index 45d3cb6a..54c90e98 100644
--- a/src/wildcard.cpp
+++ b/src/wildcard.cpp
@@ -1002,9 +1002,11 @@ void wildcard_expander_t::expand(const wcstring &base_dir, const wchar_t *wc)
/* This just trumps everything */
size_t before = this->resolved_completions->size();
this->expand(base_dir + wc_segment + L'/', wc_remainder);
- if ((this->flags & EXPAND_FUZZY_MATCH) && this->resolved_completions->size() == before)
+
+ /* Maybe try a fuzzy match (#94) if nothing was found with the literal match. Respect EXPAND_NO_DIRECTORY_ABBREVIATIONS (#2413). */
+ bool allow_fuzzy = (this->flags & (EXPAND_FUZZY_MATCH | EXPAND_NO_FUZZY_DIRECTORIES)) == EXPAND_FUZZY_MATCH;
+ if (allow_fuzzy && this->resolved_completions->size() == before)
{
- /* Nothing was found with the literal match. Try a fuzzy match (#94). */
assert(this->flags & EXPAND_FOR_COMPLETIONS);
DIR *base_dir_fd = open_dir(base_dir);
if (base_dir_fd != NULL)