From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12249 invoked from network); 11 Mar 2004 17:18:00 -0000 Received: from sunsite.dk (130.225.247.90) by ns1.primenet.com.au with SMTP; 11 Mar 2004 17:18:00 -0000 Received: (qmail 8465 invoked by alias); 11 Mar 2004 17:17:42 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 7149 Received: (qmail 8455 invoked from network); 11 Mar 2004 17:17:41 -0000 Received: from localhost (HELO sunsite.dk) (127.0.0.1) by localhost with SMTP; 11 Mar 2004 17:17:41 -0000 X-MessageWall-Score: 0 (sunsite.dk) Received: from [167.160.213.139] by sunsite.dk (MessageWall 1.0.8) with SMTP; 11 Mar 2004 17:17:41 -0000 Received: from moonbase.zanshin.com (IDENT:schaefer@localhost [127.0.0.1]) by moonbase.zanshin.com (8.12.11/8.12.11) with ESMTP id i2BHHdYe025202 for ; Thu, 11 Mar 2004 09:17:40 -0800 Received: (from schaefer@localhost) by moonbase.zanshin.com (8.12.11/8.12.11/Submit) id i2BHHdc0025201 for zsh-users@sunsite.dk; Thu, 11 Mar 2004 09:17:39 -0800 Received: (from schaefer@localhost) by candle.brasslantern.com (8.11.6/8.11.6) id i2BHHZR20355; Thu, 11 Mar 2004 09:17:35 -0800 X-Authentication-Warning: candle.brasslantern.com: schaefer set sender to schaefer@closedmail.com using -f From: Bart Schaefer Message-Id: <1040311171735.ZM20352@candle.brasslantern.com> Date: Thu, 11 Mar 2004 17:17:35 +0000 In-Reply-To: <4im0509toihq2ef1vlnnid6t93j90f6gor@4ax.com> Comments: In reply to zzapper "Re: alias vl="vi !$"" (Mar 11, 12:26pm) References: <65a050lf2u4bjch4u2uv68q56u5co0gknp@4ax.com> <20040311091003.GD844@mail.guild.uwa.edu.au> <4im0509toihq2ef1vlnnid6t93j90f6gor@4ax.com> <15272.1079008435@csr.com> <39n050dv0evle58451ugj2m1vfktsj1e1b@4ax.com> <20040311125558.GA24218@picard.franken.de> In-Reply-To: =?iso-8859-1?Q?=3C20040311125558=2EGA24218=40picard=2Efranken?= =?iso-8859-1?Q?=2Ede=3E?= =?iso-8859-1?Q?Comments=3A_In_reply_to__Thomas_K=F6hler_=3Cjean-luc=40pic?= =?iso-8859-1?Q?ard=2Efranken=2Ede=3E?= =?iso-8859-1?Q?________=22Re=3A_alias_vl=3D=22vi_!$=22=22_=28Mar_11=2C__1?= =?iso-8859-1?Q?=3A55pm=29?= In-Reply-To: Comments: In reply to zzapper "Re: alias vl="vi !$"" (Mar 11, 1:23pm) X-Mailer: Z-Mail (5.0.0 30July97) To: zsh-users@sunsite.dk Subject: Re: alias vl="vi !$" MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by moonbase.zanshin.com id i2BHHdu6025164 X-Envelope-Sender: On Mar 11, 12:26pm, zzapper wrote: > Subject: Re: alias vl="vi !$" > > On Thu, 11 Mar 2004 17:10:03 +0800, James Devenish > >on Thu, Mar 11, 2004 at 08:59:16AM +0000, zzapper wrote: > >> alias vl="vi !$" where !$ is the command line "last parameter" > > > >Make your own 'function' named `vl`? > > > Do I have access to the positional parameters of the previous command > line /history from inside a function? This brings up an interesting point. On the command line, $_ is the last word of the previous command, very much like !$ is. (In the external process environment, $_ is the path name of the currently executing command.) Inside a function, however, $_ has already been changed to be the last word of the _currently executing_ command, the same as as $argv[-1]. Which is not really all that useful, though maybe more useful than if it had been changed to the path name of zsh or some such. I'm usually a stickler for backwards compatibility, but does anyone think anything would break if the changing of $_ were delayed until after shell functions have been called, so that it would remain the last word of the _previous_ command? On Mar 11, 1:55pm, Thomas Köhler wrote: > > accept-line-or-empty-cmd() { > if [ "$LBUFFER$RBUFFER" = vl ] ; then > LBUFFER="vi !$" > RBUFFER="" > fi > builtin zle .accept-line > } Cute, but unecessarily complicated: if [[ $BUFFER = vl ]]; then BUFFER='vi !$'; fi It also doesn't really work like an alias. Consider (in csh) that vl foo would become vi !$ foo whereas your example above would grumble about vl not found. On Mar 11, 1:23pm, zzapper wrote: > > Tejmo emailed me this solution which works!! > > vl () { > gvim.exe $(history -1 | sed "s/.* //g") > } That's the right idea, but it's a lot of processes for something you could do entirely in zsh. vl () { zmodload -i zsh/parameter # Just in case vi "${${(z)history[${${(@kno)history}[-1]}]}[-1]}" "$@" } I'm tempted to just leave that unexplained, but I wont't. ${(@kno)history} history numbers in ascending order (note 1) ${${...}[-1]} last element (largest histno) (note 2) ${(z)history[...]} corresponding history entry, split to words ${${...}[-1]} last element (last word of last history entry) Note 1: The @ is only necessary because the whole thing is inside the square brackets of ${history[...]}, which forces string context. Thus the @ converts back to array context. Note 2: I'd have used ${${(@knO)history}[1]} except that's affected by the KSH_ARRAYS option. Negative subscripting isn't.