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

Re: Zsh autocompletion with no access to a parent directory

On Thu, 29 Jul 2010 08:46:47 -0700
Matt Wright <matt@xxxxxxxxxxxx> wrote:
> Apologies for necroing this thread but I've hit a snag with this
> stuff and I can't work out whats going on. I threw some debug in
> around the code you changed in _path_files but all the paths look
> sane. After that it barrels off down compfiles code and my brain
> leapt out my left armpit.
> If I do the following, using the _path_files changes you supplied me
> long ago:
> # mkdir -p /tmp/foo\~bar/test
> # ls /tmp/foo~bar/te<TAB>
> All I get is:
> [caesium: ~]$ ls /tmp/foo~bar/te
> No matches found for: `files'
> If I back up and TAB at the end of "foo~bar", zsh changes my prompt
> to:
> [caesium: ~]$ ls /tmp/foo\~bar/ 

Er, I think you'll find it's all completely, er... anyway, I've run out of

I think the following might be better (patch against the version in the
archive).  There's still one oddity where /tmp/foo~bar/te completes to
/tmp/foo\~bar/test but doesn't get recognised as a directory until you hit
tab again.  I think that's due to code down later on: probably because it's
found that the result doesn't match what was on the command line so refuses
to look and see if it's a directory.  I can't see where that's happening
but I think within compadd or compresult.

Index: Completion/Unix/Type/_path_files
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Type/_path_files,v
retrieving revision 1.52
diff -p -u -r1.52 _path_files
--- Completion/Unix/Type/_path_files	5 May 2010 09:54:38 -0000	1.52
+++ Completion/Unix/Type/_path_files	3 Aug 2010 12:52:01 -0000
@@ -367,17 +367,24 @@ for prepath in "$prepaths[@]"; do
     # Explanation of substitution: For tmp1 and tpre, which are used further
     # on, we need to remove quotes from everything that's not a pattern
     # character, because the code that does the file generation only
-    # strips qutoes from pattern characters (you know better than
+    # strips quotes from pattern characters (you know better than
     # to ask why).  Because we need to test for a real directory,
     # however, for tmp2 we unquote everything.
-    tmp1=${tmp1//(#b)\\([^\\\]\[\^\~\(\)\#\*\?])/$match[1]}
+    tmp1=${tmp1//(#b)\\(?)/$match[1]}
+    # Theory: donepath needs the quoting of special characters
+    # still in it.  However, we need it without at this point.
+    # (I think.)  Note this is different from the above where we're
+    # doing something a bit different.
+    tmp3=${donepath//(#b)\\(?)/$match[1]}
     while true; do
-      if [[ -z $path_completion || -d $prepath$realpath$donepath$tmp2 ]]; then
-	donepath=$donepath$tmp1/
+      if [[ -z $path_completion || -d $prepath$realpath$tmp3$tmp2 ]]; then
+	tmp3=$tmp3$tmp1/
+	# Now put donepath back the way it should be.  (I think.)
+	donepath=${tmp3//(#b)([\\\]\[\^\~\(\)\#\*\?])/\\$match[1]}
       elif [[ $tmp1 = (#b)(*)/([^/]#) ]]; then

Peter Stephenson <pws@xxxxxxx>            Software Engineer
Tel: +44 (0)1223 692070                   Cambridge Silicon Radio Limited
Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK

Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom

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