Zsh Mailing List Archive
Messages sorted by:
Re: Context-aware file name completion with preferences
- X-seq: zsh-users 15038
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Mikael Puhakka <mr.progo@xxxxxxxxx>
- Subject: Re: Context-aware file name completion with preferences
- Date: Sat, 1 May 2010 13:27:58 -0700
- Cc: zsh-users@xxxxxxx
- In-reply-to: <n2jd663d1bd1005010619l8468362al946bcda107870f95@xxxxxxxxxxxxxx>
- List-help: <mailto:firstname.lastname@example.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:email@example.com>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <n2jd663d1bd1005010619l8468362al946bcda107870f95@xxxxxxxxxxxxxx>
On Sat, May 1, 2010 at 6:19 AM, Mikael Puhakka <mr.progo@xxxxxxxxx> wrote:
> Of these files, I'd edit the .tex file most often: I would like zsh to
> prefer .tex files to anything else from these files. They still should
> appear in the completion cycle, but not first.
Assuming you've enabled the shell function completion system with
"compinit", you want to add some zstyle commands to your startup
In particular, you're looking for the group-name, group-order, and
tag-order styles. You use group-name to organize sets of matches,
group-order to determine the display order of those sets, and
tag-order to determine whether particular sets are offered (or not).
Well, actually most often you set group-name to the empty string and
allow zsh to name the groups for you.
zstyle ':completion:*' group-name ''
in the particular case of file completion you can use the
file-patterns style to organize sets of file names. A common setting
is something like this:
zstyle ':completion:*' file-patterns '%p:globbed-files
This means to offer globbed files and directories in the first set of
completions, and everything else if there are no globbed files or
directories among the possible matches. (A globbed-file is just one
whose name can be generated from a wildcard pattern that you may have
typed on the command line.)
You can extend this:
zstyle ':completion:*' file-patterns '*.(c|cpp|java|tex|txt):editable-files' \
'%p:globbed-files *(-/):directories' '*:all-files'
Note placement of quotes and spaces; a space inside a quoted string
separates groups that are displayed together, while a space between
quoted strings separates groups that are displayed sequentially, e.g.
you'll get editable files if there are any, then globbed files or
directories, and finally anything.
It's been a long time since I plugged this, but if you really want to
learn about this in detail you should pick up a copy of "From Bash to
Z Shell: Conquering the Command Line" from www.apress.com.
Messages sorted by: