summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBert Münnich <ber.t@posteo.de>2019-06-25 14:58:44 +0200
committerBert Münnich <ber.t@posteo.de>2019-12-06 17:57:34 +0100
commit20fc20c568171045b1844dffc0f023fe427753fc (patch)
treedf712a7c7ca61507614b5a61db3cf670b1723306
parent70324f7a8a274e0cf57e55241ba8246b2ef6ab63 (diff)
Quote matches of all custom completion functions
We only did this for external commands. Now function and variable names get quoted too, if they contain a character that needs quoting.
-rw-r--r--edit-readline.c23
1 files changed, 18 insertions, 5 deletions
diff --git a/edit-readline.c b/edit-readline.c
index 56b5970..10c1904 100644
--- a/edit-readline.c
+++ b/edit-readline.c
@@ -42,7 +42,9 @@ static char *dir_join(const char *a, const char *b) {
char *maybe_quote(char *p) {
if (strpbrk(p, quote_chars)) {
- char *r = quote(p, SINGLE_MATCH, "");
+ char *r = mprint("%#S", p);
+ if (rl_completion_suppress_quote && rl_completion_type != '*')
+ r[strlen(r)-1] = '\0';
efree(p);
return r;
}
@@ -70,7 +72,7 @@ static char *entry(char *dname, char *name, char *subdirs,
if (S_ISDIR(st.st_mode))
rl_completion_append_character = '/';
if (exe || S_ISDIR(st.st_mode))
- return maybe_quote(dir_join(subdirs, name));
+ return dir_join(subdirs, name);
return NULL;
}
@@ -178,6 +180,8 @@ static rl_compentry_func_t *compl_func(const char *text, int start, int end) {
static rl_compentry_func_t *compentry_func;
static char **rc_completion(const char *text, int start, int end) {
+ size_t i;
+ char **matches = NULL;
rl_compentry_func_t *func;
if (compentry_func != NULL) {
@@ -186,10 +190,19 @@ static char **rc_completion(const char *text, int start, int end) {
} else
func = compl_func(text, start, end);
if (func != NULL) {
+ matches = rl_completion_matches(text, func);
+ if (matches) {
+ if (matches[1])
+ rl_completion_suppress_quote = 1;
+ if (rl_completion_type != '?')
+ matches[0] = maybe_quote(matches[0]);
+ if (rl_completion_type == '*')
+ for (i = 1; matches[i]; i++)
+ matches[i] = maybe_quote(matches[i]);
+ }
rl_attempted_completion_over = 1;
- return rl_completion_matches(text, func);
- } else
- return NULL;
+ }
+ return matches;
}
static int expl_complete(rl_compentry_func_t *func, int count, int key) {