* alias vl="vi !$" @ 2004-03-11 8:59 zzapper 2004-03-11 9:10 ` James Devenish 2004-03-11 13:23 ` zzapper 0 siblings, 2 replies; 13+ messages in thread From: zzapper @ 2004-03-11 8:59 UTC (permalink / raw) To: zsh-users Hi, I've often wanted to have aliases such alias vl="vi !$" where !$ is the command line "last parameter" Doesn't work though, is there any way to do this kind of thing? zzapper (vim & cygwin & zsh) -- vim -c ":%s/^/WhfgTNabgureRIvzSUnpxre/|:%s/[R-T]/ /Ig|:normal ggVGg?" http://www.vim.org/tips/tip.php?tip_id=305 Best of Vim Tips ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: alias vl="vi !$" 2004-03-11 8:59 alias vl="vi !$" zzapper @ 2004-03-11 9:10 ` James Devenish 2004-03-11 12:26 ` zzapper 2004-03-11 13:23 ` zzapper 1 sibling, 1 reply; 13+ messages in thread From: James Devenish @ 2004-03-11 9:10 UTC (permalink / raw) To: zsh-users In message <65a050lf2u4bjch4u2uv68q56u5co0gknp@4ax.com> on Thu, Mar 11, 2004 at 08:59:16AM +0000, zzapper wrote: > alias vl="vi !$" where !$ is the command line "last parameter" > > Doesn't work though, is there any way to do this kind of thing? Make your own 'function' named `vl`? ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: alias vl="vi !$" 2004-03-11 9:10 ` James Devenish @ 2004-03-11 12:26 ` zzapper 2004-03-11 12:33 ` Peter Stephenson 0 siblings, 1 reply; 13+ messages in thread From: zzapper @ 2004-03-11 12:26 UTC (permalink / raw) To: zsh-users 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" >> >> Doesn't work though, is there any way to do this kind of thing? > >Make your own 'function' named `vl`? > > Do I have access to the positional parameters of the previous command line /history from inside a function? zzapper (vim & cygwin & zsh) -- vim -c ":%s/^/WhfgTNabgureRIvzSUnpxre/|:%s/[R-T]/ /Ig|:normal ggVGg?" http://www.vim.org/tips/tip.php?tip_id=305 Best of Vim Tips ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: alias vl="vi !$" 2004-03-11 12:26 ` zzapper @ 2004-03-11 12:33 ` Peter Stephenson 2004-03-11 12:40 ` zzapper 0 siblings, 1 reply; 13+ messages in thread From: Peter Stephenson @ 2004-03-11 12:33 UTC (permalink / raw) To: zsh-users zzapper wrote: > Do I have access to the positional parameters of the previous command > line /history from inside a function? You'll have to be more specific. Tell us exactly what you're trying to do and it will avoid all these guessing games... ********************************************************************** 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 ********************************************************************** ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: alias vl="vi !$" 2004-03-11 12:33 ` Peter Stephenson @ 2004-03-11 12:40 ` zzapper 2004-03-11 12:55 ` Thomas Köhler 0 siblings, 1 reply; 13+ messages in thread From: zzapper @ 2004-03-11 12:40 UTC (permalink / raw) To: zsh-users On Thu, 11 Mar 2004 12:33:55 +0000, Peter Stephenson wrote: On the command prompt line I'm often typing say >ll fred.txt >vi !$ Now I'd like to have an alias/function called say vl (vi last) >vl Which would save me typing vi !$ (my poor little fingers!), for that to work vl would need to access the line history zzapper (vim & cygwin & zsh) -- vim -c ":%s/^/WhfgTNabgureRIvzSUnpxre/|:%s/[R-T]/ /Ig|:normal ggVGg?" http://www.vim.org/tips/tip.php?tip_id=305 Best of Vim Tips ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: alias vl="vi !$" 2004-03-11 12:40 ` zzapper @ 2004-03-11 12:55 ` Thomas Köhler 0 siblings, 0 replies; 13+ messages in thread From: Thomas Köhler @ 2004-03-11 12:55 UTC (permalink / raw) To: zzapper; +Cc: zsh-users [-- Attachment #1: Type: text/plain, Size: 910 bytes --] Hi, zzapper wrote: > On Thu, 11 Mar 2004 12:33:55 +0000, Peter Stephenson wrote: > > On the command prompt line I'm often typing say > > >ll fred.txt > >vi !$ > > Now I'd like to have an alias/function called say vl (vi last) > > >vl > > Which would save me typing vi !$ (my poor little fingers!), for that > to work vl would need to access the line history accept-line-or-empty-cmd() { if [ "$LBUFFER$RBUFFER" = vl ] ; then LBUFFER="vi !$" RBUFFER="" fi builtin zle .accept-line } zle -N accept-line-or-empty-cmd bindkey "^M" accept-line-or-empty-cmd Fun with widgets :) Ciao, Thomas -- Thomas Köhler Email: jean-luc@picard.franken.de <>< WWW: http://jeanluc-picard.de IRC: tkoehler PGP public key available from Homepage! [-- Attachment #2: Digital signature --] [-- Type: application/pgp-signature, Size: 189 bytes --] ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: alias vl="vi !$" 2004-03-11 8:59 alias vl="vi !$" zzapper 2004-03-11 9:10 ` James Devenish @ 2004-03-11 13:23 ` zzapper 2004-03-11 17:17 ` Bart Schaefer 1 sibling, 1 reply; 13+ messages in thread From: zzapper @ 2004-03-11 13:23 UTC (permalink / raw) To: zsh-users On Thu, 11 Mar 2004 08:59:16 +0000, wrote: >Hi, >I've often wanted to have aliases such > >alias vl="vi !$" where !$ is the command line "last parameter" > Tejmo emailed me this solution which works!! vl () { gvim.exe $(history -1 | sed "s/.* //g") } zzapper (vim & cygwin & zsh) -- vim -c ":%s/^/WhfgTNabgureRIvzSUnpxre/|:%s/[R-T]/ /Ig|:normal ggVGg?" http://www.vim.org/tips/tip.php?tip_id=305 Best of Vim Tips ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: alias vl="vi !$" 2004-03-11 13:23 ` zzapper @ 2004-03-11 17:17 ` Bart Schaefer 2004-03-11 17:58 ` $_ and compatibility Danek Duvall ` (2 more replies) 0 siblings, 3 replies; 13+ messages in thread From: Bart Schaefer @ 2004-03-11 17:17 UTC (permalink / raw) To: zsh-users 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. ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: $_ and compatibility 2004-03-11 17:17 ` Bart Schaefer @ 2004-03-11 17:58 ` Danek Duvall 2004-03-11 19:05 ` alias vl="vi !$" Wayne Davison 2004-03-14 16:27 ` Peter Stephenson 2 siblings, 0 replies; 13+ messages in thread From: Danek Duvall @ 2004-03-11 17:58 UTC (permalink / raw) To: Bart Schaefer; +Cc: zsh-users On Thu, Mar 11, 2004 at 05:17:35PM +0000, Bart Schaefer wrote: > 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? Somewhere, someone would break. That's almost a given. But with a proper notice, maybe it would be okay? I think it would make sense to keep a list of (non-bug) incompatibilities somewhere in the distribution so that people would have a definitive place to find out why their stuff isn't working anymore. But it still makes it harder to incorporate zsh in a distribution that strives for backwards compatibility. :( Danek ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: alias vl="vi !$" 2004-03-11 17:17 ` Bart Schaefer 2004-03-11 17:58 ` $_ and compatibility Danek Duvall @ 2004-03-11 19:05 ` Wayne Davison 2004-03-11 20:13 ` zzapper 2004-03-14 16:27 ` Peter Stephenson 2 siblings, 1 reply; 13+ messages in thread From: Wayne Davison @ 2004-03-11 19:05 UTC (permalink / raw) To: Bart Schaefer; +Cc: zsh-users On Thu, Mar 11, 2004 at 05:17:35PM +0000, Bart Schaefer wrote: > Inside a function, however, $_ has already been changed to be the last > word of the _currently executing_ command, the same as as $argv[-1]. But it's not changed in an alias, so the simplest approach would appear to be: alias vl='vi $_' That works for me. ..wayne.. ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: alias vl="vi !$" 2004-03-11 19:05 ` alias vl="vi !$" Wayne Davison @ 2004-03-11 20:13 ` zzapper 2004-03-11 23:45 ` Thorsten Kampe 0 siblings, 1 reply; 13+ messages in thread From: zzapper @ 2004-03-11 20:13 UTC (permalink / raw) To: zsh-users On Thu, 11 Mar 2004 11:05:53 -0800, wrote: >On Thu, Mar 11, 2004 at 05:17:35PM +0000, Bart Schaefer wrote: >> Inside a function, however, $_ has already been changed to be the last >> word of the _currently executing_ command, the same as as $argv[-1]. > >But it's not changed in an alias, so the simplest approach would appear >to be: > > alias vl='vi $_' > >That works for me. > >..wayne.. That is so wunderbar!!! But in fact I like all the answers to this thread!!! zzapper (vim & cygwin & zsh) -- vim -c ":%s/^/WhfgTNabgureRIvzSUnpxre/|:%s/[R-T]/ /Ig|:normal ggVGg?" http://www.vim.org/tips/tip.php?tip_id=305 Best of Vim Tips ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: alias vl="vi !$" 2004-03-11 20:13 ` zzapper @ 2004-03-11 23:45 ` Thorsten Kampe 0 siblings, 0 replies; 13+ messages in thread From: Thorsten Kampe @ 2004-03-11 23:45 UTC (permalink / raw) To: zsh-users * zzapper (2004-03-11 21:13 +0100) > On Thu, 11 Mar 2004 11:05:53 -0800, wrote: >>On Thu, Mar 11, 2004 at 05:17:35PM +0000, Bart Schaefer wrote: >>> Inside a function, however, $_ has already been changed to be the last >>> word of the _currently executing_ command, the same as as $argv[-1]. >> >>But it's not changed in an alias, so the simplest approach would appear >>to be: >> >> alias vl='vi $_' > > That is so wunderbar!!! And the most wonderful thing is that you probably don't need all that stuff (alias, function) and simply type "vi [Alt]+[.]" ("insert-last-word"). Because this is common sequence like cat <deletable_file> rm <deletable_file> it doesn't make sense to make aliases or functions for all the countless possibilities. Thorsten ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: alias vl="vi !$" 2004-03-11 17:17 ` Bart Schaefer 2004-03-11 17:58 ` $_ and compatibility Danek Duvall 2004-03-11 19:05 ` alias vl="vi !$" Wayne Davison @ 2004-03-14 16:27 ` Peter Stephenson 2 siblings, 0 replies; 13+ messages in thread From: Peter Stephenson @ 2004-03-14 16:27 UTC (permalink / raw) To: Bart Schaefer; +Cc: zsh-users Bart Schaefer wrote: > 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? It's not likely anyone's using the present form in a function; after all there are better ways of getting the current arguments inside a function, and if the command entered isn't simply the function (there's a more complicated expression), it's hard to see why you would want the last argument. -- Peter Stephenson <pws@pwstephenson.fsnet.co.uk> Work: pws@csr.com Web: http://www.pwstephenson.fsnet.co.uk ^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2004-03-14 16:25 UTC | newest] Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2004-03-11 8:59 alias vl="vi !$" zzapper 2004-03-11 9:10 ` James Devenish 2004-03-11 12:26 ` zzapper 2004-03-11 12:33 ` Peter Stephenson 2004-03-11 12:40 ` zzapper 2004-03-11 12:55 ` Thomas Köhler 2004-03-11 13:23 ` zzapper 2004-03-11 17:17 ` Bart Schaefer 2004-03-11 17:58 ` $_ and compatibility Danek Duvall 2004-03-11 19:05 ` alias vl="vi !$" Wayne Davison 2004-03-11 20:13 ` zzapper 2004-03-11 23:45 ` Thorsten Kampe 2004-03-14 16:27 ` Peter Stephenson
Code repositories for project(s) associated with this public inbox https://git.vuxu.org/mirror/zsh/ This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).