diff options
author | Sven Wischnowsky <wischnow@users.sourceforge.net> | 2000-08-08 10:32:47 +0000 |
---|---|---|
committer | Sven Wischnowsky <wischnow@users.sourceforge.net> | 2000-08-08 10:32:47 +0000 |
commit | 5c90cf1a51b176badb0095a089df132fc5f62746 (patch) | |
tree | d2117774926e1e19959dd0c24f6810a289b050ec | |
parent | 40e4f4c40b8da652eded74fb3c607c2fb289a10f (diff) | |
download | zsh-5c90cf1a51b176badb0095a089df132fc5f62746.tar.gz zsh-5c90cf1a51b176badb0095a089df132fc5f62746.tar.xz zsh-5c90cf1a51b176badb0095a089df132fc5f62746.zip |
more fixes for completion of special characters (quoting) (12565)
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | Completion/Core/_expand | 6 | ||||
-rw-r--r-- | Completion/Core/_path_files | 27 | ||||
-rw-r--r-- | Doc/Zsh/mod_computil.yo | 6 | ||||
-rw-r--r-- | Src/Zle/computil.c | 40 |
5 files changed, 60 insertions, 25 deletions
diff --git a/ChangeLog b/ChangeLog index 9da7640b0..902dcf003 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2000-08-08 Sven Wischnowsky <wischnow@zsh.org> + + * 12565: Completion/Core/_expand, Completion/Core/_path_files, + Doc/Zsh/mod_computil.yo, Src/Zle/computil.c: more fixes for + completion of special characters (quoting) + 2000-08-08 Peter Stephenson <pws@csr.com> * unposted: Src/xmods.conf, Src/Aliases/*: Remove Src/Aliases diff --git a/Completion/Core/_expand b/Completion/Core/_expand index bcc357ead..9e7d3d122 100644 --- a/Completion/Core/_expand +++ b/Completion/Core/_expand @@ -63,7 +63,7 @@ if [[ "$force" = *s* ]] || eval exp\=\( ${${(q)exp}:gs/\\{/\{/:gs/\\}/\}/} \) eval 'exp=( ${${(e)exp//\\[ ]/ }//(#b)([ -\\])/\\$match[1]} )' 2>/dev/null +])/\\$match[1]} )' 2>/dev/null else exp=( ${exp:s/\\\$/\$} ) fi @@ -77,14 +77,14 @@ subd=("$exp[@]") # Now try globbing. [[ "$force" = *g* ]] || zstyle -T ":completion:${curcontext}:" glob && - eval 'exp=( ${~exp} ); exp=( ${exp//(#b)([][()|*?^#~<>\\])/\\${match[1]}} )' 2>/dev/null + eval 'exp=( ${~exp} ); exp=( ${exp//(#b)([][()|*?^#~<>\\=])/\\${match[1]}} )' 2>/dev/null # If we don't have any expansions or only one and that is the same # as the original string, we let other completers run. (( $#exp )) || exp=("$subd[@]") -[[ $#exp -eq 1 && "$exp[1]" = "$word"(|\(N\)) ]] && return 1 +[[ $#exp -eq 1 && "${exp[1]//\\}" = "${word//\\}"(|\(N\)) ]] && return 1 # With subst-globs-only we bail out if there were no glob expansions, # regardless of any substitutions diff --git a/Completion/Core/_path_files b/Completion/Core/_path_files index 8bb00bdf9..23d32cc0f 100644 --- a/Completion/Core/_path_files +++ b/Completion/Core/_path_files @@ -421,7 +421,7 @@ for prepath in "$prepaths[@]"; do # There are more components, so skip over the next components and make a # slash be added. - tmp1=( ${tmp1//(#b)([][()|*?^#~<>\\])/\\${match[1]}} ) + tmp1=( ${tmp1//(#b)([][()|*?^#~<>\\=])/\\${match[1]}} ) tmp2="${(M)tpre##((.|..|)/)##}" if [[ -n "$tmp2" ]]; then skipped="/$tmp2" @@ -470,7 +470,14 @@ for prepath in "$prepaths[@]"; do # it as far as possible. tmp2="$testpath" - compquote tmp1 tmp2 + if [[ -n "$linepath" ]]; then + compquote -p tmp2 tmp1 + elif [[ -n "$tmp2" ]]; then + compquote -p tmp1 + compquote tmp2 + else + compquote tmp1 tmp2 + fi if [[ -n $menu || -z "$compstate[insert]" ]] || ! zstyle -t ":completion:${curcontext}:paths" expand suffix; then @@ -544,7 +551,12 @@ for prepath in "$prepaths[@]"; do tmp4="${testpath#${mid}}" tmp3="${mid%/*/}" tmp2="${${mid%/}##*/}" - compquote tmp4 tmp3 tmp2 tmp1 + if [[ -n "$linepath" ]]; then + compquote -p tmp3 + else + compquote tmp3 + fi + compquote tmp4 tmp2 tmp1 for i in "$tmp1[@]"; do compadd -Qf "$mopts[@]" -p "$linepath$tmp3/" -s "/$tmp4$i" \ -W "$prepath$realpath${mid%/*/}/" \ @@ -559,7 +571,14 @@ for prepath in "$prepaths[@]"; do SUFFIX="${osuf}" fi tmp4="$testpath" - compquote tmp4 tmp1 + if [[ -n "$linepath" ]]; then + compquote -p tmp4 tmp1 + elif [[ -n "$tmp4" ]]; then + compquote -p tmp1 + compquote tmp4 + else + compquote tmp4 tmp1 + fi compadd -Qf "$mopts[@]" -p "$linepath$tmp4" -W "$prepath$realpath$testpath" \ "$pfxsfx[@]" -M "r:|/=* r:|=*" -a tmp1 fi diff --git a/Doc/Zsh/mod_computil.yo b/Doc/Zsh/mod_computil.yo index a0bc3767d..8d50c4a45 100644 --- a/Doc/Zsh/mod_computil.yo +++ b/Doc/Zsh/mod_computil.yo @@ -61,7 +61,7 @@ and unsorted, both without removing duplicates, with removing all duplicates and with removing consecutive duplicates). ) findex(compquote) -item(tt(compquote) var(names) ...)( +item(tt(compquote) [ tt(-p) ] var(names) ...)( There may be reasons to write completion functions that have to add the matches using the tt(-Q) option to tt(compadd) and perform quoting themselves. Instead of interpreting the first character of the @@ -69,7 +69,9 @@ tt(all_quotes) key of the tt(compstate) special association and using the tt(q) flag for parameter expansions, one can use this builtin command. The arguments are the names of scalar or array parameters and the values of these parameters are quoted as needed for the -innermost quoting level. +innermost quoting level. If the tt(-p) option is given, quoting is +done as if there is some prefix before the values of the parameters, +so that a leading equal sign will not be quoted. The return value is non-zero in case of an error and zero otherwise. ) diff --git a/Src/Zle/computil.c b/Src/Zle/computil.c index 54c2a0f19..863f15fa1 100644 --- a/Src/Zle/computil.c +++ b/Src/Zle/computil.c @@ -2559,6 +2559,24 @@ bin_compvalues(char *nam, char **args, char *ops, int func) return 1; } +static char * +comp_quote(char *str, int prefix) +{ + int x; + char *ret; + + if ((x = (prefix && *str == '='))) + *str = 'x'; + + ret = bslashquote(str, NULL, (*compqstack == '\'' ? 1 : + (*compqstack == '"' ? 2 : 0))); + + if (x) + *str = *ret = '='; + + return ret; +} + static int bin_compquote(char *nam, char **args, char *ops, int func) { @@ -2578,15 +2596,7 @@ bin_compquote(char *nam, char **args, char *ops, int func) if ((v = getvalue(&vbuf, &name, 0))) { switch (PM_TYPE(v->pm->flags)) { case PM_SCALAR: - { - char *val = getstrvalue(v); - - val = bslashquote(val, NULL, - (*compqstack == '\'' ? 1 : - (*compqstack == '"' ? 2 : 0))); - - setstrvalue(v, ztrdup(val)); - } + setstrvalue(v, ztrdup(comp_quote(getstrvalue(v), ops['p']))); break; case PM_ARRAY: { @@ -2596,10 +2606,7 @@ bin_compquote(char *nam, char **args, char *ops, int func) char **p = new; for (; *val; val++, p++) - *p = ztrdup(bslashquote(*val, NULL, - (*compqstack == '\'' ? 1 : - (*compqstack == '"' ? 2 : - 0)))); + *p = ztrdup(comp_quote(*val, ops['p'])); *p = NULL; setarrvalue(v, new); @@ -3242,11 +3249,12 @@ cfp_opt_pats(char **pats, char *matcher) if (*s != '\\' || !s[1] || s[1] == '*' || s[1] == '?' || s[1] == '<' || s[1] == '>' || s[1] == '(' || s[1] == ')' || s[1] == '[' || s[1] == ']' || s[1] == '|' || s[1] == '#' || - s[1] == '^' || s[1] == '~') { + s[1] == '^' || s[1] == '~' || s[1] == '=') { if ((s == compprefix || s[-1] != '\\') && (*s == '*' || *s == '?' || *s == '<' || *s == '>' || *s == '(' || *s == ')' || *s == '[' || *s == ']' || - *s == '|' || *s == '#' || *s == '^' || *s == '~')) + *s == '|' || *s == '#' || *s == '^' || *s == '~' || + *s == '=')) *t++ = '\\'; *t++ = *s; } @@ -3653,7 +3661,7 @@ static struct builtin bintab[] = { BUILTIN("compdescribe", 0, bin_compdescribe, 3, -1, 0, NULL, NULL), BUILTIN("comparguments", 0, bin_comparguments, 1, -1, 0, NULL, NULL), BUILTIN("compvalues", 0, bin_compvalues, 1, -1, 0, NULL, NULL), - BUILTIN("compquote", 0, bin_compquote, 1, -1, 0, NULL, NULL), + BUILTIN("compquote", 0, bin_compquote, 1, -1, 0, "p", NULL), BUILTIN("comptags", 0, bin_comptags, 1, -1, 0, NULL, NULL), BUILTIN("comptry", 0, bin_comptry, 0, -1, 0, NULL, NULL), BUILTIN("compfiles", 0, bin_compfiles, 1, -1, 0, NULL, NULL), |