zsh-users
 help / color / mirror / code / Atom feed
* refering to 2nd from last history parameter?
@ 2015-01-22 12:18 zzapper
  2015-01-22 12:57 ` Peter Stephenson
                   ` (2 more replies)
  0 siblings, 3 replies; 14+ messages in thread
From: zzapper @ 2015-01-22 12:18 UTC (permalink / raw)
  To: zsh-users

Hi
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

-- 
zzapper
https://twitter.com/dailyzshtip

---
This email has been checked for viruses by Avast antivirus software.
http://www.avast.com



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: refering to 2nd from last history parameter?
  2015-01-22 12:18 refering to 2nd from last history parameter? zzapper
@ 2015-01-22 12:57 ` Peter Stephenson
  2015-01-22 13:34   ` zzapper
                     ` (2 more replies)
  2015-01-22 13:40 ` Axel Beckert
  2015-01-22 17:17 ` Bart Schaefer
  2 siblings, 3 replies; 14+ messages in thread
From: Peter Stephenson @ 2015-01-22 12:57 UTC (permalink / raw)
  To: zsh-user

[-- Attachment #1: Type: text/plain, Size: 907 bytes --]

On Thu, 22 Jan 2015 12:18:19 +0000
zzapper <david@rayninfo.co.uk> 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

This isn't actually a question :-).  What are you trying to do?  Are you
at the shell command line trying to extract something and don't care if
you use the editor or history, but happen to know there was a way to do
something a bit like this in the history?  I'll assume that but let us
know if that's not the case.

You can use the insert-last-word standard widget (\e. in Emacs mode)
combined with the copy-earlier-word shell widget, which I have bound as

autoload -Uz copy-earlier-word
zle -N copy-earlier-word
bindkey '\e=' copy-earlier-word

Then the answer is that you type "\e." to get the h then "\e=" to go
back to the "g".  I use this all the time.

pws

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: refering to 2nd from last history parameter?
  2015-01-22 12:57 ` Peter Stephenson
@ 2015-01-22 13:34   ` zzapper
  2015-01-23 19:59   ` Wayne Davison
  2015-01-26 12:05   ` zzapper
  2 siblings, 0 replies; 14+ messages in thread
From: zzapper @ 2015-01-22 13:34 UTC (permalink / raw)
  To: zsh-users

Peter Stephenson <p.w.stephenson@ntlworld.com> wrote in 
news:CAECNH1RyC2Q-5y3Ynk-F+cJvtRvFPWdvcpDOqXmrJB=uSJCbTQ@mail.gmail.com:

> On Thu, 22 Jan 2015 12:18:19 +0000
> zzapper <david@rayninfo.co.uk> 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
> 
> This isn't actually a question :-).  What are you trying to do?  Are 
you
> at the shell command line trying to extract something and don't care 

Peter
I realised I hadn't been clear.

echo a b c d e f g h

echo !:7
g

but it would be cuter if I could specify

echo !:$-1   ### doesnt work

but is there anyway to do this?
(I may have asked this before)





---
This email has been checked for viruses by Avast antivirus software.
http://www.avast.com



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: refering to 2nd from last history parameter?
  2015-01-22 12:18 refering to 2nd from last history parameter? zzapper
  2015-01-22 12:57 ` Peter Stephenson
@ 2015-01-22 13:40 ` Axel Beckert
  2015-01-22 15:52   ` ZyX
  2015-01-22 17:17 ` Bart Schaefer
  2 siblings, 1 reply; 14+ messages in thread
From: Axel Beckert @ 2015-01-22 13:40 UTC (permalink / raw)
  To: zsh-users

Hi,

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@deuxchevaux.org  (Mail)
 X   See http://www.nonhtmlmail.org/campaign.html | abe@noone.org (Mail+Jabber)
/ \  I love long mails: http://email.is-not-s.ms/ | http://abe.noone.org/ (Web)


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: refering to 2nd from last history parameter?
  2015-01-22 13:40 ` Axel Beckert
@ 2015-01-22 15:52   ` ZyX
  2015-01-22 16:09     ` Axel Beckert
  0 siblings, 1 reply; 14+ messages in thread
From: ZyX @ 2015-01-22 15:52 UTC (permalink / raw)
  To: Axel Beckert, zsh-users



22.01.2015, 16:42, "Axel Beckert" <abe@deuxchevaux.org>:
> Hi,
>
> 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 is documented:“x-y    A range of words; x *defaults to 0*.”

>
> 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 "!:$"? :-)

I would say that `!:<1` resulting in a second word counted from the end is rather unexpected.

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


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: refering to 2nd from last history parameter?
  2015-01-22 15:52   ` ZyX
@ 2015-01-22 16:09     ` Axel Beckert
  0 siblings, 0 replies; 14+ messages in thread
From: Axel Beckert @ 2015-01-22 16:09 UTC (permalink / raw)
  To: zsh-users

Hi,

On Thu, Jan 22, 2015 at 06:52:01PM +0300, ZyX wrote:
> > 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 is documented:“x-y    A range of words; x *defaults to 0*.”

Thanks for the heads up. I actually expected (and looked for) a
literal mention of "-x".

> > 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 "!:$"? :-)
> 
> I would say that `!:<1` resulting in a second word counted from the end is rather unexpected.

Yeah, well, depends. :-)

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


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: refering to 2nd from last history parameter?
  2015-01-22 12:18 refering to 2nd from last history parameter? zzapper
  2015-01-22 12:57 ` Peter Stephenson
  2015-01-22 13:40 ` Axel Beckert
@ 2015-01-22 17:17 ` Bart Schaefer
  2015-01-22 17:51   ` zzapper
  2 siblings, 1 reply; 14+ messages in thread
From: Bart Schaefer @ 2015-01-22 17:17 UTC (permalink / raw)
  To: zsh-users

On Jan 22, 12:18pm, zzapper wrote:
}
} 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

Not exactly pretty, but in two steps:

    !!:-:p
    echo !!:$


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: refering to 2nd from last history parameter?
  2015-01-22 17:17 ` Bart Schaefer
@ 2015-01-22 17:51   ` zzapper
  0 siblings, 0 replies; 14+ messages in thread
From: zzapper @ 2015-01-22 17:51 UTC (permalink / raw)
  To: zsh-users

Bart Schaefer <schaefer@brasslantern.com> wrote in 
news:150122091734.ZM11366@torch.brasslantern.com:

> On Jan 22, 12:18pm, zzapper wrote:
> }
> } 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
> 
> Not exactly pretty, but in two steps:
> 
>     !!:-:p
>     echo !!:$
> 

 !:-:p isn't that a smiley?



-- 
zzapper
https://twitter.com/dailyzshtip

---
This email has been checked for viruses by Avast antivirus software.
http://www.avast.com



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: refering to 2nd from last history parameter?
  2015-01-22 12:57 ` Peter Stephenson
  2015-01-22 13:34   ` zzapper
@ 2015-01-23 19:59   ` Wayne Davison
  2015-01-26 12:05   ` zzapper
  2 siblings, 0 replies; 14+ messages in thread
From: Wayne Davison @ 2015-01-23 19:59 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: zsh-user

[-- Attachment #1: Type: text/plain, Size: 402 bytes --]

On Thu, Jan 22, 2015 at 4:57 AM, Peter Stephenson <
p.w.stephenson@ntlworld.com> wrote:

> Then the answer is that you type "\e." to get the h then "\e=" to go
> back to the "g".


An alternative to using copy-earlier-word is to use a numeric arg to get
earlier words with insert-last-word. e.g. \e2\e. will give you the
2nd-to-last word ("g") directly, so you can count from right to left.

..wayne..

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: refering to 2nd from last history parameter?
  2015-01-22 12:57 ` Peter Stephenson
  2015-01-22 13:34   ` zzapper
  2015-01-23 19:59   ` Wayne Davison
@ 2015-01-26 12:05   ` zzapper
  2015-01-26 12:16     ` Peter Stephenson
  2 siblings, 1 reply; 14+ messages in thread
From: zzapper @ 2015-01-26 12:05 UTC (permalink / raw)
  To: zsh-users

Peter Stephenson <p.w.stephenson@ntlworld.com> wrote in 
news:CAECNH1RyC2Q-5y3Ynk-F+cJvtRvFPWdvcpDOqXmrJB=uSJCbTQ@mail.gmail.com:

> On Thu, 22 Jan 2015 12:18:19 +0000
> zzapper <david@rayninfo.co.uk> 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
> 
> This isn't actually a question :-).  What are you trying to do?  Are 
you
PWS
I didn't immediately appreciate your alternative solution

########### alt. and alt=
bindkey '\e.' insert-last-word
autoload -Uz copy-earlier-word
zle -N copy-earlier-word
bindkey '\e=' copy-earlier-word

Still think it's a pity that there's no !$-1 , !$-2 etc

BTW if you tab complete
echo !$-1 
I get !3569NVXZhikms1



-- 
zzapper
https://twitter.com/dailyzshtip

---
This email has been checked for viruses by Avast antivirus software.
http://www.avast.com



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: refering to 2nd from last history parameter?
  2015-01-26 12:05   ` zzapper
@ 2015-01-26 12:16     ` Peter Stephenson
  2015-01-26 13:17       ` Axel Beckert
  0 siblings, 1 reply; 14+ messages in thread
From: Peter Stephenson @ 2015-01-26 12:16 UTC (permalink / raw)
  To: zsh-users

On Mon, 26 Jan 2015 12:05:14 +0000
zzapper <david@rayninfo.co.uk> wrote:
> Still think it's a pity that there's no !$-1 , !$-2 etc

The summary of the discussion is that there is, but it means the wrong
thing: "-" is always a range in history arguments.  Clearly this
isn't what you actually want here, or ever would.

We could special case the meaning here: given that ranges have to be in
order, a range starting with "$" is by definition useless.  It's a bit
kludgy but this is !-history so it's hard to imagine anyone looking for
elegance.  Does this break anything?

I was wondering about using a different character, but I think any
solution where "minus" is not encoded by "-" is too obscure to be
useful.

pws


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: refering to 2nd from last history parameter?
  2015-01-26 12:16     ` Peter Stephenson
@ 2015-01-26 13:17       ` Axel Beckert
  2015-01-26 14:32         ` Peter Stephenson
  0 siblings, 1 reply; 14+ messages in thread
From: Axel Beckert @ 2015-01-26 13:17 UTC (permalink / raw)
  To: zsh-users

Hi,

On Mon, Jan 26, 2015 at 12:16:49PM +0000, Peter Stephenson wrote:
> On Mon, 26 Jan 2015 12:05:14 +0000
> We could special case the meaning here: given that ranges have to be in
> order, a range starting with "$" is by definition useless.  It's a bit
> kludgy but this is !-history so it's hard to imagine anyone looking for
> elegance.  Does this break anything?

Depends.

I'd expect that

  mkdir foo
  mv foo foo-1

can be abbreviated 

  mkdir foo
  mv !$ !$-1

i.e. that anything behind "!$" except a colon (as in "!$:t" or "!$:h")
is taken literal.

> I was wondering about using a different character, but I think any
> solution where "minus" is not encoded by "-" is too obscure to be
> useful.

I'd still prefer the form of "!!:<1" or shorter "!<2" instead of
anything involving further characters after "$".

Additionally, I thought we're talking about picking a single argument
counting from the back, not from ranges of arguments -- which then could
be "!<2-4" or "!<4-2". (I'd allow both forms as both can make sense.)

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


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: refering to 2nd from last history parameter?
  2015-01-26 13:17       ` Axel Beckert
@ 2015-01-26 14:32         ` Peter Stephenson
  2015-01-26 21:30           ` Axel Beckert
  0 siblings, 1 reply; 14+ messages in thread
From: Peter Stephenson @ 2015-01-26 14:32 UTC (permalink / raw)
  To: zsh-users

On Mon, 26 Jan 2015 14:17:23 +0100
Axel Beckert <abe@deuxchevaux.org> wrote:
> On Mon, Jan 26, 2015 at 12:16:49PM +0000, Peter Stephenson wrote:
> > On Mon, 26 Jan 2015 12:05:14 +0000
> > We could special case the meaning here: given that ranges have to be in
> > order, a range starting with "$" is by definition useless.  It's a bit
> > kludgy but this is !-history so it's hard to imagine anyone looking for
> > elegance.  Does this break anything?
> 
> Depends.
> 
> I'd expect that
> 
>   mkdir foo
>   mv foo foo-1
> 
> can be abbreviated 
> 
>   mkdir foo
>   mv !$ !$-1
> 
> i.e. that anything behind "!$" except a colon (as in "!$:t" or "!$:h")
> is taken literal.

That's not how it works at the moment --- because "-" means a range,
!$-1 alread has a special meaning, as you'll see if you try it.

> > I was wondering about using a different character, but I think any
> > solution where "minus" is not encoded by "-" is too obscure to be
> > useful.
> 
> I'd still prefer the form of "!!:<1" or shorter "!<2" instead of
> anything involving further characters after "$".

That's probably doable and easy enough to remember.  History's early
enough that normal syntactic meanings aren't relevant.

> Additionally, I thought we're talking about picking a single argument
> counting from the back, not from ranges of arguments -- which then could
> be "!<2-4" or "!<4-2". (I'd allow both forms as both can make sense.)

Yes, we are, but the point is "-" already *means* range and isn't going
to stop doing that.

pws


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: refering to 2nd from last history parameter?
  2015-01-26 14:32         ` Peter Stephenson
@ 2015-01-26 21:30           ` Axel Beckert
  0 siblings, 0 replies; 14+ messages in thread
From: Axel Beckert @ 2015-01-26 21:30 UTC (permalink / raw)
  To: zsh-users

Hi Peter,

On Mon, Jan 26, 2015 at 02:32:12PM +0000, Peter Stephenson wrote:
> > I'd expect that
> > 
> >   mkdir foo
> >   mv foo foo-1
> > 
> > can be abbreviated 
> > 
> >   mkdir foo
> >   mv !$ !$-1
> > 
> > i.e. that anything behind "!$" except a colon (as in "!$:t" or "!$:h")
> > is taken literal.
> 
> That's not how it works at the moment --- because "-" means a range,
> !$-1 alread has a special meaning, as you'll see if you try it.

Indeed:

→ echo foo bar
foo bar
→ echo !$-1
zsh: no such word in event

I must admit, I'm surprised that I obviously never ran into that.

Thanks for the heads up!

> > Additionally, I thought we're talking about picking a single argument
> > counting from the back, not from ranges of arguments -- which then could
> > be "!<2-4" or "!<4-2". (I'd allow both forms as both can make sense.)
> 
> Yes, we are, but the point is "-" already *means* range and isn't going
> to stop doing that.

*nod*

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


^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2015-01-26 21:30 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-22 12:18 refering to 2nd from last history parameter? zzapper
2015-01-22 12:57 ` Peter Stephenson
2015-01-22 13:34   ` zzapper
2015-01-23 19:59   ` Wayne Davison
2015-01-26 12:05   ` zzapper
2015-01-26 12:16     ` Peter Stephenson
2015-01-26 13:17       ` Axel Beckert
2015-01-26 14:32         ` Peter Stephenson
2015-01-26 21:30           ` Axel Beckert
2015-01-22 13:40 ` Axel Beckert
2015-01-22 15:52   ` ZyX
2015-01-22 16:09     ` Axel Beckert
2015-01-22 17:17 ` Bart Schaefer
2015-01-22 17:51   ` zzapper

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).