Escape separators (colon and equals) to improve completion

Fish completes parts of words split by the separators, so things like
`dd if=/dev/sd<TAB>` work.
This commit improves interactive completion if completion strings legitimately
contain '=' or ':'.  Consider this example where completion will suggest
a:a:1 and other files in the cwd in addition to a:1

touch a:1; complete -C'ls a:'

This behavior remains unchanged, but this commit allows to quote or escape
separators, so that e.g. `ls "a:<TAB>` and `ls a\:<TAB>` successfully complete
the filename.

This also makes the completion insert those escapes automatically unless
already quoted.
So `ls a<TAB>` will give `ls a\:1`.

Both changes match bash's behavior.
This commit is contained in:
Johannes Altmanninger
2019-08-23 20:58:42 +02:00
committed by ridiculousfish
parent 54ed2ad440
commit f7dac82ed6
6 changed files with 24 additions and 13 deletions

View File

@@ -488,7 +488,6 @@ class reader_data_t : public std::enable_shared_from_this<reader_data_t> {
static volatile sig_atomic_t interrupted = 0;
// Prototypes for a bunch of functions defined later on.
static bool is_backslashed(const wcstring &str, size_t pos);
static wchar_t unescaped_quote(const wcstring &str, size_t pos);
/// Mode on startup, which we restore on exit.
@@ -2297,9 +2296,7 @@ static int can_read(int fd) {
return select(fd + 1, &fds, 0, 0, &can_read_timeout) == 1;
}
/// Test if the specified character in the specified string is backslashed. pos may be at the end of
/// the string, which indicates if there is a trailing backslash.
static bool is_backslashed(const wcstring &str, size_t pos) {
bool is_backslashed(const wcstring &str, size_t pos) {
// note pos == str.size() is OK.
if (pos > str.size()) return false;