Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
File completion with **/ (with solution)
- X-seq: zsh-users 21953
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: File completion with **/ (with solution)
- Date: Tue, 20 Sep 2016 17:56:23 -0700
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=from:message-id:date:to:subject:mime-version; bh=QjcYyaV9QBjRronKUZ+ybVm5iHlPYq7xhfVirIJQHSc=; b=U7+kscAULbNdwlslIBAv2NGYz90bp4KTYOGUAhxJ0GwM18mgqml5h32+wsIRPlGZ3t ntyHXBNRmw7/AiuyhAHgewEVqqmIXxPh3lTwLBa78ltphj+Uwt+XGVwjsNEQfoyglbiK LCtSq4nh+VOQBh8Kf8cGPW8sNcnz3FBYslr4uHAv6KLeByrurrekQXJhBpj9xmXcW/Qe pLH3V4CzvsDS1+THFhYaltPRPFrMGW/7Z6D1qFvYPATO8++e6eTj/n/JnxbSOXGVc30q tvwMt4RtGwGNW3l5lbHLhARF3mKKetOEaLsSfD6V9uJBaOu1jRwMl+KRl9f8Cv5Kac9R 33fA==
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
This started out as an email to ponder/grumble about why _match can't
resolve a recursive glob. Along the way I discovered a way to accomplish
what I wanted ... but I'll leave the leading expository stuff for context,
having taken the time to write it.
Using the _match completer, I can do (in the zsh source tree)
% ls C*/*/*/_main<TAB>
to get the expected result of
% ls Completion/Base/Core/_main_complete
On the other hand, if I do
% ls C*/**/_main<TAB>
I get no result.
If I have the _expand completer and manually append a "*" before hitting
TAB, I also get the desired result. Or if I have _complete and do
ls C///_main<TAB>
then _path_files does magic for me, but I have to use the exact correct
number of slashes, which is precisely what I want to avoid doing.
The "problem" with _match is that it doesn't change the way that possible
completions are generated; it only changes the way the word on the line
is compared to the possible completions to select the candidate matches.
It was at this point that I re-read the doc for the _user_expand completer
for the first time in years.
_user_expand looks up the array-valued style "user-expand" and steps
through the array until one of the elements yields at least one possible
completion, by assigning it to the $reply array. You can read the doc
to find out what the elements look like. There are several things about
_user_expand that could be improved with features of more recent zsh,
and the doc doesn't cover all the other styles it recognized / tags it
uses, so that needs update too. However, it's perfect for solving the
problem I just described:
_glob_expand() { reply=( $~1* ) }
zstyle :completion::user-expand:: user-expand _glob_expand
zstyle :completion::user-expand:: tag-order expansions all-expansions
zstyle ':completion:*' completer _expand _complete _match _user_expand
The other thing it might be useful to call out in the doc is to note that
because _user_expand is called AS a completer, it has access to more of
the zstyle $context when it is called than when the "completer" style is
looked up. This could be handy when deciding what to assign to $reply.
It would mostly work to include other completers / completion functions
as elements of the user-expand array, but note that they'll ALL be tried
(rather than only tried until at least one finds a match), because the
functions normally won't assign to $reply and that is currently the only
way to stop walking the elements.
Daniel, this might be the "better answer" to your _match question, too.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author