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

Re: setopt globcomplete and () broken

On Tue, 10 Mar 2009 14:25:16 +0100
Mikael Magnusson <mikachu@xxxxxxxxx> wrote:
> This is something that has been broken forever, but I never bothered
> to look into exactly what broke it in my config. Today I got annoyed
> enough though.
> zsh -f
> % autoload compinit; compinit
> % mkdir newdir; cd newdir
> % touch '()' '().'
> % touch <tab>
> % touch \(\)<tab>
> \(\)   \(\).
> % setopt globcomplete
> % touch <tab>
> % touch \(\)<tab>
> # nothing appears
> I can only reproduce it with a pair of parentheses, just ( or )
> doesn't trigger it, but text can appear between them and still trigger
> it. The oldest version I tried was 4.2.5 and the newest some days old
> cvs.

The following chunk of code in guess-where around line 201 is triggering:
it's looking for glob qualifiers.  We need a test that the parentheses
aren't quoted; we could have '()' or "()" or $'()' or \(\), or some
mixture, possibly with text in between.  There is a slightly better test
higher up, around line 17 (which correctly didn't trigger): that's newer
code that I added when completing glob qualifiers.  (The chunk of code
below isn't completing them, it's trying to ensure they get applied.)
Possibly copying the newer test here or putting it into a separate function
would help, but I will wait for any cries of enlightenment before I do

It would be quite nice to have a test for the shell to decide "is character
N in this command line argument a token or a metacharacter?" which isn't so
much more than the context lex horrors already do...  I suppose
parse-partial-sexp is out of the question.

if [[ -n "$compstate[pattern_match]" &&
      ( ( -z "$SUFFIX" && "$PREFIX" = (|*[^\$])\([^\|\~]##\) ) ||
        "$SUFFIX" =  (|*[^\$])\([^\|\~]##\) ) ]]; then
  # Copy all glob qualifiers from the line to
  # the patterns used when generating matches
  if [[ "$SUFFIX" = *\([^\|\~]##\) ]]; then
  for tmp1 in "$pats[@]"; do
    if [[ "$tmp1" = (#b)(*[^\$])"(#q"(*)")" ]]; then
      tmp2=( "$tmp2[@]" "${match[1]}(#q${tmp3}${match[2]})" )
    elif [[ "$tmp1" = (#b)(*[^\$])(\(\([^\|~]##\)\)) ]]; then
      tmp2=( "$tmp2[@]" "${match[1]}((${tmp3}${match[2][3,-1]}" )
    elif [[ "$tmp1" = (#b)(*[^\$])(\([^\|~]##\)) ]]; then
      tmp2=( "$tmp2[@]" "${match[1]}(${tmp3}${match[2][2,-1]}" )
      tmp2=( "$tmp2[@]" "${tmp1}(${tmp3})" )
  pats=( "$tmp2[@]" )

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

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