Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: [BUG] single-quote problem in completion quoting



Bart Schaefer wrote:
> I don't think this is the same.  In Marlon's example, the single quote
> is not completing as part of the file name, it's being treated as the
> opening quote of a string.  There's actually not a missing last single
> quote, rather there's an extra last single quote.  Completion is
> trying to close the opened quoted string but the replacement done by
> compadd isn't in the right form for that.

You can replicate this by comparing just:
    compadd "test'"

against:
    tmp1=( "test'" )
    compquote tmp1
    compadd -Q -a tmp1

To overcome the effects of -Q, _path_files should also be passing
-S "$compstate[quote]" to compadd. The following patch (which I won't
commit) demonstrates. There may be other problems with this but the main
one I noticed is that a suffix specified with -S takes precedence over
any automatic "/" suffix added for a directory due to compadd's -f option.
Short of reimplementing it, there's no way for _path_files to know in
advance whether compadd -f will insert a directory.

My own opinion is that with compadd -f, the automatic "/" suffix for a
directory should take precedence over whatever was passed with -S.
(And the first character of it would be used as an auto-remove character
for the / suffix).

Oliver

diff --git a/Completion/Unix/Type/_path_files b/Completion/Unix/Type/_path_files
index d46dcbe5a..40cd43f9e 100644
--- a/Completion/Unix/Type/_path_files
+++ b/Completion/Unix/Type/_path_files
@@ -43,7 +43,7 @@ fi
 
 local linepath realpath donepath prepath testpath exppath skips skipped
 local tmp1 tmp2 tmp3 tmp4 i orig eorig pre suf tpre tsuf opre osuf cpre
-local pats haspats ignore pfx pfxsfx sopt gopt opt sdirs ignpar cfopt listsfx
+local pats haspats ignore pfx pfxsfx sfx sopt gopt opt sdirs ignpar cfopt listsfx
 local nm=$compstate[nmatches] menu matcher mopts sort mid accex fake
 local listfiles listopts tmpdisp origtmp1 Uopt
 local accept_exact_dirs path_completion
@@ -57,7 +57,7 @@ exppaths=()
 # Get the options.
 
 zparseopts -a mopts \
-    'P:=pfx' 'S:=pfxsfx' 'q=pfxsfx' 'r:=pfxsfx' 'R:=pfxsfx' \
+    'P:=pfx' 'S:=sfx' 'q=pfxsfx' 'r:=pfxsfx' 'R:=pfxsfx' \
     'W:=prepaths' 'F:=ignore' 'M+:=matcher' \
     J+: V+: x+: X+: 1 2 o+: n 'f=tmp1' '/=tmp1' 'g+:-=tmp1'
 
@@ -73,6 +73,7 @@ else
 fi
 pats=( "${(@)pats:# #}" )
 
+pfxsfx=( -S "${compstate[quote]}${sfx[2]:- }" "$pfxsfx[@]" )
 if (( $#pfx )); then
   compset -P "${(b)pfx[2]}" || pfxsfx=( "$pfx[@]" "$pfxsfx[@]" )
 fi




Messages sorted by: Reverse Date, Date, Thread, Author