Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: refering to 2nd from last history parameter?


On Thu, Jan 22, 2015 at 12:18:19PM +0000, zzapper wrote:
> I don't think it's possible
> ls !$    last parameter of previous command
> echo a b c d e f g h
> I don't think I can grab 'g' without counting left to right

Interesting question.

I would have expected that using negativ numbers would work (with
CSH_JUNKIE_HISTORY enabled of course):

  % echo !:-2

But this actually seems an abbreviation for

  % echo !:0-2

despite this is not documented in the man page. (I may come up with a
documentation patch for that later.)

It though seems consistent with tcsh which behaves the same way.

Despite I never thought about it so far, I'd use such a feature if I
knew it exists. Would come in handy with many rsync/scp/cp/etc.
command-lines to reuse the source argument if there were a bunch of
dashed options before it.

I wonder what would be a good syntax for such a feature as "-n"
seems already taken. Maybe something "<n" as in e.g.

  % echo !:<2

(And would we count from 0 or from 1, i.e. would "!:<0" or "!:<1" be a
synonym for "!:$"? :-)

		Kind regards, Axel
/~\  Plain Text Ribbon Campaign                   | Axel Beckert
\ /  Say No to HTML in E-Mail and News            | abe@xxxxxxxxxxxxxxx  (Mail)
 X   See http://www.nonhtmlmail.org/campaign.html | abe@xxxxxxxxx (Mail+Jabber)
/ \  I love long mails: http://email.is-not-s.ms/ | http://abe.noone.org/ (Web)

Messages sorted by: Reverse Date, Date, Thread, Author