From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22142 invoked by alias); 7 Dec 2015 12:08:05 -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: 21061 Received: (qmail 10665 invoked from network); 7 Dec 2015 12:07:55 -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=1449489413; bh=XaGZGMGUhkv2twbxLQocqTUHjCTzn/FePCcbyKW/r4w=; h=From:To:In-Reply-To:References:Subject:Date; b=VwNVvK4ihDm6qr5kd/SxPs+javcTmx/mQntusL/9rbwosv9zQxonV0NTGXSyQWgzN jZRb+87Xpvrl5tky/LaSjTCp26eMK2gRW7udXSnXJ4dHBjHjhU7+y5TWu6cVOHoKin 8EGyjpcIzB/nr1rJ3+s7y5R+9lBUMPPRPRvh/oJ8= 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: <484471449489412@web12j.yandex.ru> X-Mailer: Yamail [ http://yandex.ru ] 5.0 Date: Mon, 07 Dec 2015 14:56:52 +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 >   } I have pseudo-alias commands like zmw and zpy which do automagic escaping of their arguments (e.g. `zpy import zsh; print(zsh.getvalue("PATH"))` transforms into `zpython "import zsh; print(zsh.getvalue(\"PATH\"))"`) by hooking accept-line zle widget: _-accept-line () { emulate -L zsh local -r autopushd=${options[autopushd]} options[autopushd]=off cd $PWD || cd options[autopushd]=$autopushd if [[ ${BUFFER[1,3]} = ":h " ]] then _HISTLINE=$BUFFER BUFFER=":h ${(q)BUFFER[4,-1]}" elif [[ ${BUFFER[1,4]} = "zmw " ]] then _HISTLINE=$BUFFER BUFFER="zmw "${(j. .)${(q)${(z)BUFFER[5,-1]}}} elif [[ ${BUFFER[1,4]} = "zpy " ]] then _HISTLINE=$BUFFER BUFFER="zpython ${(qqq)BUFFER[5,-1]}" fi zle .accept-line } zle -N accept-line _-accept-line . You may use the same technique to do anything you like with the line you typed, though this “anything” will sometimes be rather tricky to implement. `(z)` parameter expansion flag will be very useful on this path. > > Ciao > > Dominik ^_^ ^_^ > > -- > > Dominik Vogt > IBM Germany