From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8440 invoked from network); 11 Oct 2007 09:00:35 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.3 (2007-08-08) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.2.3 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 11 Oct 2007 09:00:35 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 96126 invoked from network); 11 Oct 2007 09:00:29 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 11 Oct 2007 09:00:29 -0000 Received: (qmail 13805 invoked by alias); 11 Oct 2007 09:00:26 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 23934 Received: (qmail 13790 invoked from network); 11 Oct 2007 09:00:26 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 11 Oct 2007 09:00:26 -0000 Received: (qmail 95911 invoked from network); 11 Oct 2007 09:00:26 -0000 Received: from cluster-g.mailcontrol.com (85.115.41.190) by a.mx.sunsite.dk with SMTP; 11 Oct 2007 09:00:18 -0000 Received: from cameurexb01.EUROPE.ROOT.PRI ([62.189.241.200]) by rly09g.srv.mailcontrol.com (MailControl) with ESMTP id l9B8xsKT013796 for ; Thu, 11 Oct 2007 10:00:11 +0100 Received: from news01 ([10.103.143.38]) by cameurexb01.EUROPE.ROOT.PRI with Microsoft SMTPSVC(6.0.3790.1830); Thu, 11 Oct 2007 09:59:24 +0100 Date: Thu, 11 Oct 2007 09:59:24 +0100 From: Peter Stephenson To: zsh-workers@sunsite.dk Subject: Re: expand-and-quote-alias Message-ID: <20071011095924.0f3afcc0@news01> In-Reply-To: References: Organization: CSR X-Mailer: Claws Mail 3.0.0 (GTK+ 2.10.14; i386-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-OriginalArrivalTime: 11 Oct 2007 08:59:24.0876 (UTC) FILETIME=[058F68C0:01C80BE5] X-Scanned-By: MailControl A-07-08-10 (www.mailcontrol.com) on 10.71.0.119 On Wed, 10 Oct 2007 22:58:41 +0000 (UTC) J=C3=B6rg Sommer wrote: > sometimes I want to not the whole alias. But expand-alias is useless, > because the expansion still uses the alias. >=20 > % alias ls=3D'ls --color -lA' >=20 > I want it without -A >=20 > % ls > % ls --color -lA >=20 > But this is >=20 > % ls --color -lA --color -lA >=20 > How can I do something like the following with one key, e.g. ^Xa >=20 > % ls > % 'ls --color -lA' >=20 > But, mhh, this is still not what I want. I want this: >=20 > % 'ls' --color -lA You can safely set the whole alias to something along these lines, alias ls=3D'\ls --color -lA' say (a single "\" is enough to inhibit alias expansion). With a little more work you can make _expand_alias do that. You probably want to base it on the latest version from the archive since there was a bug that it used to remove quoting (although that doesn't quite impinge on the problem in question). Care is needed since if the alias expansion starts with a special character you definitely don't want to add a backslash. With even more effort you can split it into words, see if the first word is the same as the original first word, and only add the backslash in that case. This is non-invasive enough to be worth applying to the archive. Here's the complete result. It's not perfect but it handles normal cases like the present one. #compdef -K _expand_alias complete-word \C-xa local word expl tmp pre sel what local -a tmpa eval "$_comp_setup" if [[ -n $funcstack[2] ]]; then if [[ "$funcstack[2]" =3D _prefix ]]; then word=3D"$IPREFIX$PREFIX$SUFFIX" else word=3D"$IPREFIX$PREFIX$SUFFIX$ISUFFIX" fi pre=3D() else local curcontext=3D"$curcontext" if [[ -z "$curcontext" ]]; then curcontext=3D"expand-alias-word:::" else curcontext=3D"expand-alias-word:${curcontext#*:}" fi word=3D"$IPREFIX$PREFIX$SUFFIX$ISUFFIX" pre=3D(_main_complete - aliases) fi zstyle -s ":completion:${curcontext}:" regular tmp || tmp=3Dyes case $tmp in always) sel=3Dr;; yes|1|true|on) [[ CURRENT -eq 1 ]] && sel=3Dr;; esac zstyle -T ":completion:${curcontext}:" global && sel=3D"g$sel" zstyle -t ":completion:${curcontext}:" disabled && sel=3D"${sel}${(U)sel}" tmp=3D [[ $sel =3D *r* ]] && tmp=3D$aliases[$word] [[ -z $tmp && $sel =3D *g* ]] && tmp=3D$galiases[$word] [[ -z $tmp && $sel =3D *R* ]] && tmp=3D$dis_aliases[$word] [[ -z $tmp && $sel =3D *G* ]] && tmp=3D$dis_galiases[$word] if [[ -n $tmp ]]; then # We used to remove the quoting from the value in the parameter. # That was probably just an oversight: an alias is always replaced # literally. tmp=3D${tmp%%[[:blank:]]##} if [[ $tmp[1] =3D [[:alnum:]_] ]]; then tmpa=3D(${(z)tmp}) if [[ $tmpa[1] =3D $word && $tmp =3D $aliases[$word] ]]; then # This is an active regular alias and the first word in the result # is the same as what was on the line already. Quote it so # that it doesn't get reexanded on execution. # # Strictly we also need to check if the original word matches # a later word in the expansion and the previous words are # all aliases where the expansion ends in " ", but I'm # too lazy. tmp=3D"\\$tmp" fi fi $pre _wanted aliases expl alias compadd -UQ ${tmp%%[[:blank:]]##} elif (( $#pre )) && zstyle -t ":completion:${curcontext}:" complete; then $pre _aliases -s "$sel" -S '' else return 1 fi --=20 Peter Stephenson Software Engineer CSR PLC, Churchill House, Cambridge Business Park, Cowley Road Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070