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

Re: Filtering argument lists (e.g. for grep)



On Mon, 7 Dec 2015 11:56:22 +0100
Dominik Vogt <vogt@xxxxxxxxxxxxxxxxxx> wrote:
> For some commands, there are some file patterns that I never want
> to pass to the command (unless explicitly stated otherwise).  For
> example, grep'ing should normally ignore backup and ChangeLog files
> 
>  *ChangeLog*
>  *~
>  \#*
> 
> Maybe grep is a bad example because this can be done with the
> --exclude= option.  But could zsh help filtering the names
> generated by globbing in a more general way so that I could write
> 
>   $ <foo> *
> 
> and have zsh automagically filter the results of the * (not
> everywhere; only for commands that have this feature enabled) so
> that the non-matching names are not passed to the command in the
> first place?

You could use a global alias, e.g.

alias -g '@*'='*~(*\~|\#*|ChangeLog)'

Ig you want that first * to be something more flexible you can use a
glob qualifier.

  gi () {
    [[ $REPLY != (*\~|\#*|ChangeLog) ]]
  }

and use

  <foo> *(+gi)

pws



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