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

@@ -523,7 +523,8 @@ void parse_util_get_parameter_info(const wcstring &cmd, const size_t pos, wchar_
wcstring parse_util_escape_string_with_quote(const wcstring &cmd, wchar_t quote, bool no_tilde) {
wcstring result;
if (quote == L'\0') {
escape_flags_t flags = ESCAPE_ALL | ESCAPE_NO_QUOTED | (no_tilde ? ESCAPE_NO_TILDE : 0);
escape_flags_t flags =
ESCAPE_ALL | ESCAPE_NO_QUOTED | (no_tilde ? ESCAPE_NO_TILDE : 0) | ESCAPE_SEPARATORS;
result = escape_string(cmd, flags);
} else {
// Here we are going to escape a string with quotes.