aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar ridiculousfish <corydoras@ridiculousfish.com>2014-11-06 10:07:26 -0800
committerGravatar ridiculousfish <corydoras@ridiculousfish.com>2014-11-06 10:13:33 -0800
commit701a37fd00a37563bd4645e6a0c93144dd1b0551 (patch)
tree2c1cd503e9a3e367847bdc199ecd3148c088788f
parent9d7fbd2cc0627fa41944ba2fb7e2d6e1396467d0 (diff)
Fix to avoid shortening the command line on tab completions.
This prevents cases like `cd /usr/e` from tab-completing to `cd /usr/` (which is the shared prefix of the tab completions). Things are still sort of confusing with fuzzy matching, e.g. with files like this: foo1bar foo2bar Then ba<tab> will replace the token with foo. That's surprising, but not new to this fix. Fixes #1727
-rw-r--r--reader.cpp8
1 files changed, 6 insertions, 2 deletions
diff --git a/reader.cpp b/reader.cpp
index 84c36497..9e1afd22 100644
--- a/reader.cpp
+++ b/reader.cpp
@@ -1883,8 +1883,12 @@ static bool handle_completions(const std::vector<completion_t> &comp, bool conti
break;
}
}
+
+ /* Determine if we use the prefix. We use it if it's non-empty and it will actually make the command line longer. It may make the command line longer by virtue of not using REPLACE_TOKEN (so it always appends to the command line), or by virtue of replacing the token but being longer than it. */
+ bool use_prefix = common_prefix.size() > (will_replace_token ? tok.size() : 0);
+ assert(! use_prefix || ! common_prefix.empty());
- if (! common_prefix.empty())
+ if (use_prefix)
{
/* We got something. If more than one completion contributed, then it means we have a prefix; don't insert a space after it */
if (prefix_is_partial_completion)
@@ -1893,7 +1897,7 @@ static bool handle_completions(const std::vector<completion_t> &comp, bool conti
success = true;
}
- if (continue_after_prefix_insertion || common_prefix.empty())
+ if (continue_after_prefix_insertion || ! use_prefix)
{
/* We didn't get a common prefix, or we want to print the list anyways. */
size_t len, prefix_start = 0;