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

Re: Tab completion of multiple files using curly braces



On Feb 20,  9:14am, Allan Caffee wrote:
}
} With my current setup tab completion of a word with curly braces in it
} (e.g. foo{bar,biz}) Zsh expands it.  For example:
} 
} % diff ./{old,new}/obnoxiously_long_f<TAB>
} 
} I'd really like to have the shell avoid expansion and instead look for
} possible completions using the union of the file names under all
} expansions.

This is unfortunately quite difficult.  Completion is really designed
to resolve one argument to one matching string; what you're in effect
asking for here is to simultaneously complete two arguments at once.
This doesn't even work with glob completion; e.g. if instead you try

% diff ./(old|new)/ob<TAB>

or even

% diff ./*/ob<TAB>

it'll first insist that you resolve the pattern part down to one or
the other of old or new before proceeding to complete path tails.

You can't do this by adding another completer like _expand or _match.
Those are invoked at too high a level.  To make this work you'd have
to hijack file completion somewhere down in the guts of _path_files,
and pass "{old,new}' directly to compadd -Q so the brace expression
(or pattern in the glob case) becomes part of the completion result;
and *then* when completing the later portions of the path I believe
you'd need to do the comparisons yourself to assure that the full
result really does match all branches of the brace expression.

However, you might almost be able to get what you want from the
_expand completer by simply appending a "*" to the argument before
you complete, and then accept the all-expansions group of matches.
E.g.:

% diff ./{old,new}/obnoxiously_long_f*<TAB>

should offer something like (among other stuff):

Completing all expansions
./old/obnoxiously_long_file_name.c ./new/obnoxiously_long_file_name.c

and it wouldn't be so difficult to whip up something to automatically
insert that "*" before attempting the expansion.



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