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

Re: "keep-prefix true" feature request



On Apr 12,  7:30pm, Wayne Davison wrote:
} Subject: "keep-prefix true" feature request
}
}   % cd ~xpkg/apache$htd/<TAB>
}
} Now it's just beeping at me unless I change the '~' into a '$'.  

This comes from the test at line 193 of _path_files.  If there's a
leading tilde, it expands the tilde-expression but never expands the
stuff to the right of the first slash.  If there's no leading tilde,
the branch at line 244 is taken and everything gets expanded.

(This is also why your "automatic hash -d" doesn't work:  it expands
the tilde-expression by checking whether there is already a dirstack
entry, not by actually evaluating the expression.)

It *seems* to work just to swap those two branches (test for $ first,
then leading tilde), and in fact that *also* seems to handle this:

} I'd like the "keep-prefix true" setting to work a little differently.
} It keeps a variable from expanding only if it is the first item in the
} filename, and I'd like it to avoid expanding any variable that has
} text after it (like the old completion system does).

I'm sure somebody can explain to me why the following is wrong.

Index: Completion/Unix/Type/_path_files
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Type/_path_files,v
retrieving revision 1.1
diff -u -r1.1 _path_files
--- Completion/Unix/Type/_path_files	2001/04/02 11:36:27	1.1
+++ Completion/Unix/Type/_path_files	2001/04/13 04:44:16
@@ -190,7 +190,23 @@
 
 # Now let's have a closer look at the string to complete.
 
-if [[ "$pre[1]" = \~ && -z "$compstate[quote]" ]]; then
+if [[ "$pre" = *\$*/* && "$compstate[quote]" != \" ]]; then
+
+  # If there is a parameter expansion in the word from the line, we try
+  # to complete the beast by expanding the prefix and completing anything
+  # after the first slash after the parameter expansion.
+  # This fails for things like `f/$foo/b/<TAB>' where the first `f' is
+  # meant as a partial path.
+
+  linepath="${(M)pre##*\$[^/]##/}"
+  eval 'realpath=${(e)~linepath}' 2>/dev/null
+  [[ -z "$realpath" || "$realpath" = "$linepath" ]] && return 1
+  pre="${pre#${linepath}}"
+  i="${#linepath//[^\\/]}"
+  orig="${orig[1,(in:i:)/][1,-2]}"
+  donepath=
+  prepaths=( '' )
+elif [[ "$pre[1]" = \~ && -z "$compstate[quote]" ]]; then
   # It begins with `~', so remember anything before the first slash to be able
   # to report it to the completion code. Also get an expanded version of it
   # (in `realpath'), so that we can generate the matches. Then remove that
@@ -239,22 +255,6 @@
   [[ "$realpath" = "$linepath" ]] && return 1
   pre="${pre#*/}"
   orig="${orig#*/}"
-  donepath=
-  prepaths=( '' )
-elif [[ "$pre" = *\$*/* && "$compstate[quote]" != \" ]]; then
-
-  # If there is a parameter expansion in the word from the line, we try
-  # to complete the beast by expanding the prefix and completing anything
-  # after the first slash after the parameter expansion.
-  # This fails for things like `f/$foo/b/<TAB>' where the first `f' is
-  # meant as a partial path.
-
-  linepath="${(M)pre##*\$[^/]##/}"
-  eval 'realpath=${(e)~linepath}' 2>/dev/null
-  [[ -z "$realpath" || "$realpath" = "$linepath" ]] && return 1
-  pre="${pre#${linepath}}"
-  i="${#linepath//[^\\/]}"
-  orig="${orig[1,(in:i:)/][1,-2]}"
   donepath=
   prepaths=( '' )
 else

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   



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