From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16571 invoked from network); 17 May 2005 14:47:58 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 17 May 2005 14:47:58 -0000 Received: (qmail 76508 invoked from network); 17 May 2005 14:47:52 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 17 May 2005 14:47:52 -0000 Received: (qmail 2808 invoked by alias); 17 May 2005 14:47:44 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 8848 Received: (qmail 2794 invoked from network); 17 May 2005 14:47:43 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 17 May 2005 14:47:43 -0000 Received: (qmail 75412 invoked from network); 17 May 2005 14:47:43 -0000 Received: from mailhost1.csr.com (HELO MAILSWEEPER01.csr.com) (81.105.217.43) by a.mx.sunsite.dk with SMTP; 17 May 2005 14:47:31 -0000 Received: from exchange03.csr.com (unverified [10.100.137.60]) by MAILSWEEPER01.csr.com (Content Technologies SMTPRS 4.3.12) with ESMTP id for ; Tue, 17 May 2005 15:45:44 +0100 Received: from news01.csr.com ([10.103.143.38]) by exchange03.csr.com with Microsoft SMTPSVC(5.0.2195.6713); Tue, 17 May 2005 15:48:53 +0100 Received: from news01.csr.com (localhost.localdomain [127.0.0.1]) by news01.csr.com (8.13.1/8.12.11) with ESMTP id j4HElURl011347 for ; Tue, 17 May 2005 15:47:30 +0100 Received: from csr.com (pws@localhost) by news01.csr.com (8.13.1/8.13.1/Submit) with ESMTP id j4HElTUj011344 for ; Tue, 17 May 2005 15:47:29 +0100 Message-Id: <200505171447.j4HElTUj011344@news01.csr.com> X-Authentication-Warning: news01.csr.com: pws owned process doing -bs To: Zsh User Subject: Re: which-command help In-reply-to: <20050517132000.GB9627@let.rug.nl> References: <20050517132000.GB9627@let.rug.nl> Date: Tue, 17 May 2005 15:47:28 +0100 From: Peter Stephenson X-OriginalArrivalTime: 17 May 2005 14:48:53.0508 (UTC) FILETIME=[8B8FFC40:01C55AEF] X-Spam-Checker-Version: SpamAssassin 3.0.2 on a.mx.sunsite.dk X-Spam-Level: X-Spam-Status: No, score=-2.6 required=6.0 tests=AWL,BAYES_00 autolearn=ham version=3.0.2 X-Spam-Hits: -2.6 Francisco Borges wrote: > Hello, > > I can't get which-command ("^[?") to work as I would like: > > ~ % whence -c ls > ls: aliased to /bin/ls -h -N --color=auto -F -v > > ~ % alias which-command='whence -c' > # If I just run the command I get > > ~ % which-command ls > ls: aliased to /bin/ls -h -N --color=auto -F -v > > # but if I use "^[?" (is which-command) I get: > > ~ % which-command /bin/ls > /bin/ls > > How can I get ^[? to behave the same as a command line "which-command"? The problem is that the processing of which-command within the editor expands the alias, so that the command line that which-command sees already has the /bin/ls expanded. I think this is a bug, fixed below: we don't want to expand aliases when getting the name of the command. For now, you can use a workaround along the lines of: unalias which-command zle -N which-command which-command() { zle -I; whence -c ${${(zQ)LBUFFER}[1]}; } That should cover almost any case where the builtin editor function works. (Don't forget the "unalias": the interaction between aliases and function definitions isn't pretty.) I note that quoted forms of the command don't work with the builtin implementation of which-command, i.e. you can't expand 'ls' or \ls. That's a bug, but it's rather harder to fix---probably not *that* hard, though I haven't worked out the best way. That's one area where the function works better. However, it's still not smart enough to realise that if the word is quoted it's not subject to alias expansion. Hmm, actually... which-command() { zle -I local -a wds wds=(${(z)LBUFFER}) local wd=${wds[1]} local rawwd=${(Q)wd} # replace "whence -c" with your favourite function # (but NOT which-command!) if [[ $rawwd != $wd ]]; then # quoted, don't expand alias (unalias -- $rawwd 2>/dev/null; whence -c $rawwd) else # turn on globsubst for =ls etc. whence -c ${~rawwd} fi } It also handles =cmd and even baroque constructions like /bin/l[sS] correctly. Unless anyone can see a flaw, I think I can probably recommend this over the builtin editor function. Index: Src/Zle/zle_tricky.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_tricky.c,v retrieving revision 1.51 diff -u -r1.51 zle_tricky.c --- Src/Zle/zle_tricky.c 23 Feb 2005 13:50:45 -0000 1.51 +++ Src/Zle/zle_tricky.c 17 May 2005 14:18:31 -0000 @@ -2354,8 +2354,10 @@ getcurcmd(void) { int curlincmd; + int onoaliases = noaliases; char *s = NULL; + noaliases = 1; zleparse = 2; lexsave(); metafy_line(); @@ -2381,6 +2383,7 @@ inpop(); errflag = zleparse = 0; lexrestore(); + noaliases = onoaliases; return s; } -- Peter Stephenson Software Engineer CSR PLC, Churchill House, Cambridge Business Park, Cowley Road Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070 ********************************************************************** This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the system manager. **********************************************************************