From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9807 invoked from network); 16 Nov 2004 14:23:29 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 16 Nov 2004 14:23:29 -0000 Received: (qmail 22455 invoked from network); 16 Nov 2004 14:23:23 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 16 Nov 2004 14:23:23 -0000 Received: (qmail 17167 invoked by alias); 16 Nov 2004 14:22:33 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 8219 Received: (qmail 17158 invoked from network); 16 Nov 2004 14:22:32 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 16 Nov 2004 14:22:32 -0000 Received: (qmail 21196 invoked from network); 16 Nov 2004 14:22:32 -0000 Received: from mailhost1.csr.com (HELO MAILSWEEPER01.csr.com) (81.105.217.43) by a.mx.sunsite.dk with SMTP; 16 Nov 2004 14:22: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, 16 Nov 2004 14:21:20 +0000 Received: from news01.csr.com ([10.103.143.38]) by exchange03.csr.com with Microsoft SMTPSVC(5.0.2195.6713); Tue, 16 Nov 2004 14:22:19 +0000 Received: from news01.csr.com (localhost.localdomain [127.0.0.1]) by news01.csr.com (8.12.11/8.12.11) with ESMTP id iAGEMT56032707 for ; Tue, 16 Nov 2004 14:22:29 GMT Received: from csr.com (pws@localhost) by news01.csr.com (8.12.11/8.12.11/Submit) with ESMTP id iAGEMTuv032704 for ; Tue, 16 Nov 2004 14:22:29 GMT Message-Id: <200411161422.iAGEMTuv032704@news01.csr.com> X-Authentication-Warning: news01.csr.com: pws owned process doing -bs To: zsh-users@sunsite.dk Subject: Re: !!:$ In-reply-to: <20041116134539.GB14064@pegleg.valdosta.edu> References: <20041116134539.GB14064@pegleg.valdosta.edu> Date: Tue, 16 Nov 2004 14:22:28 +0000 From: Peter Stephenson X-OriginalArrivalTime: 16 Nov 2004 14:22:19.0286 (UTC) FILETIME=[AE268360:01C4CBE7] X-Spam-Checker-Version: SpamAssassin 2.63 on a.mx.sunsite.dk X-Spam-Level: X-Spam-Status: No, hits=0.0 required=6.0 tests=none autolearn=no version=2.63 X-Spam-Hits: 0.0 keef wrote: > yarr mateys! Er, yeah. > consider the following: > > % touch somefile > % chmod 755 !!:$ > > -this essentially will chmod 755 the last arg in the previous history cmd > > now then, id like to incorporate this into my .zshrc > > something to the effect of: > alias ch="chmod 755 !!:$" Try: alias ch='chmod 755 $_' It works in this case, but you can't get the full effect of history expansion in an alias since they are expanded too late. The zsh/parameter module does have $history and $historywords to help access the history, but unfortunately the interface isn't very easy to use in a case like this. $history is an associative array and you need to know the event number, which currently isn't available as a parameter: you can get it from a prompt, but not directly. This strikes me as a curious omission. How about adding it using the same name as bash? Then you can always get the full previous line as $history[$((HISTCMD-1))]. Hence you can do lots of tricks. The equivalent of the above would be: ch() { # Don't want ksh_arrays, ... emulate -L zsh # Make sure the parameter module is loaded zmodload -i zsh/parameter local prev # Split the previous line using normal shell word splitting. prev=(${(z)history[$((HISTCMD-1))]}) # Retrieve the final element of the line. chmod 755 $prev[-1] } Index: Doc/Zsh/params.yo =================================================================== RCS file: /cvsroot/zsh/zsh/Doc/Zsh/params.yo,v retrieving revision 1.23 diff -u -r1.23 params.yo --- Doc/Zsh/params.yo 8 Oct 2004 14:37:24 -0000 1.23 +++ Doc/Zsh/params.yo 16 Nov 2004 14:17:28 -0000 @@ -535,6 +535,12 @@ command under a different group ID by `tt(LPAR()GID=)var(gid)tt(; command+RPAR())' ) +vindex(HISTCMD) +item(tt(HISTCMD))( +The current history line number in an interactive shell, in other +words the line number for the command that caused tt($HISTCMD) +to be read. +) vindex(HOST) item(tt(HOST))( The current hostname. Index: Doc/Zsh/zle.yo =================================================================== RCS file: /cvsroot/zsh/zsh/Doc/Zsh/zle.yo,v retrieving revision 1.44 diff -u -r1.44 zle.yo --- Doc/Zsh/zle.yo 22 Sep 2004 04:37:02 -0000 1.44 +++ Doc/Zsh/zle.yo 16 Nov 2004 14:17:29 -0000 @@ -645,7 +645,10 @@ The current history number. Setting this has the same effect as moving up or down in the history to the corresponding history line. An attempt to set it is ignored if the line is not stored in the -history. +history. Note this is not the same as the parameter tt(HISTCMD), +which always give the number of the history line being added to the main +shell's history. tt(HISTNO) refers to the line being retrieved within +zle. ) vindex(KEYMAP) item(tt(KEYMAP) (scalar))( Index: Src/params.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/params.c,v retrieving revision 1.92 diff -u -r1.92 params.c --- Src/params.c 1 Oct 2004 19:48:57 -0000 1.92 +++ Src/params.c 16 Nov 2004 14:17:30 -0000 @@ -184,6 +184,7 @@ IPDEF4("!", &lastpid), IPDEF4("$", &mypid), IPDEF4("?", &lastval), +IPDEF4("HISTCMD", &curhist), IPDEF4("LINENO", &lineno), IPDEF4("PPID", &ppid), -- 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. This footnote also confirms that this email message has been swept by MIMEsweeper for the presence of computer viruses. www.mimesweeper.com **********************************************************************