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

Re: Context-aware file name completion with preferences



Whoah! Thanks for a thorough explanation on how this works! The book
looks tasty and doesn't cost a fortune, I'll order it if you recommend
it. Seems to me that you know your way with zsh. Is there any other
book recommendation for mastering zsh?

--Mikael

On Sat, May 1, 2010 at 23:27, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> On Sat, May 1, 2010 at 6:19 AM, Mikael Puhakka <mr.progo@xxxxxxxxx> wrote:
>>
>> Doc1.tex
>> Doc1.aux
>> Doc1.dvi
>> Doc1.log
>> ...
>>
>> 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
> files.
>
> 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
> *(-/):directories' '*:all-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: Reverse Date, Date, Thread, Author