From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21184 invoked by alias); 7 Dec 2015 12:15:27 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 21062 Received: (qmail 11227 invoked from network); 7 Dec 2015 12:15:26 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1449489825; bh=hyLkfpFEqRczeBbV64iYFsx+7h0kRKNkYbsnuJdPZ7I=; h=From:To:In-Reply-To:References:Subject:Date; b=Rxn/niuFQsIQpgWms8wW5TWEyrX1OoA4MZ/ZQIBkR9ssJRbhpzYyw/jNksr/ZBhRh TaAVo3DjV/h+y4vVc/vN9jfmWTk0mwqjFUeb9VN9cckGO/dCo5REGwKkHLt6qO3BHa 7rBnLwNh7ALOt9eJg1rJggslPoRq/zhJ+WLSa4CY= From: "Nikolay Aleksandrovich Pavlov (ZyX)" To: "vogt@linux.vnet.ibm.com" , Zsh Users In-Reply-To: <20151207113941.GA24545@linux.vnet.ibm.com> References: <20151207105622.GA18231@linux.vnet.ibm.com> <20151207112354.5d24de89@pwslap01u.europe.root.pri> <20151207113941.GA24545@linux.vnet.ibm.com> Subject: Re: Filtering argument lists (e.g. for grep) MIME-Version: 1.0 Message-Id: <531031449489824@web12j.yandex.ru> X-Mailer: Yamail [ http://yandex.ru ] 5.0 Date: Mon, 07 Dec 2015 15:03:44 +0300 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=utf-8 07.12.2015, 14:51, "Dominik Vogt" : > On Mon, Dec 07, 2015 at 11:23:54AM +0000, Peter Stephenson wrote: >>  On Mon, 7 Dec 2015 11:56:22 +0100 >>  Dominik Vogt wrote: >>  > 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 >>  > >>  > $ * >>  > >>  > 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)' > > Yes, but then I'd need an alias for every potential pattern, e.g. > @*.s*, @**/*, @*.c.* etc. > >>  Ig you want that first * to be something more flexible you can use a >>  glob qualifier. >> >>    gi () { >>      [[ $REPLY != (*\~|\#*|ChangeLog) ]] >>    } >> >>  and use >> >>     *(+gi) > > That sounds good, but is there a way to make that qualifier a > default for certain commands? As an alternative, is it possible > to access the command name from inside the qualifier function? > >   function gi () { >     if ; then >       [[ $REPLY != (*\~|\#*|ChangeLog) ]] >     fi >   } And there is another possibility: considering you want to do this thing with command `foo` you need to do the following: 1. Create an alias `foo='noglob foo'`. 2. Create a function `foo` like this: function foo() { local -a args=( "${@[@]}" ) local -a new_args for (( I=2; I<= $#args; I++ )) ; do if [[ $args[I] != ${${args[I]}//[*?]} ]] ; then # If argument contains glob pattern args[I]+="(+gi)" new_args=( $~args[I] ) args[I,I]=( $new_args ) (( I += #new_args - 1 )) fi done command foo "${args[@]}" } . I.e. in place of leaving zsh to expand globs, expand it in your function “manually”, with necessary additions. > > Ciao > > Dominik ^_^ ^_^ > > -- > > Dominik Vogt > IBM Germany