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

Re: History expansion surprisingly sets event designator



On Tue, 6 Jun 2017 17:50:03 +0200
Leah Neukirchen <leah@xxxxxxxx> wrote:
> Hi,
> 
> on #zsh we discovered:
> 
> zsh 5.3.1 (x86_64-unknown-linux-gnu)
> zsh-5.3.1-0-g06b1b7a    (and zsh-5.3.1-204-g62c4169, via danielsh)
> % zsh -f
> juno% printf a b c
> a%
> juno% echo x y z
> x y z
> juno% echo !printf:2<TAB><DEL>!:3<RET>
> c
>
> The first tab expansion will correctly expand to "b", but it changes
> the event designator to the printf-line, resulting in !:3 expanding to "c",
> while the typed in line "echo !:3" itself would refer to the previous
> line, the echo-line, and should result in "z".
> (Same for tab-expanding the second history reference.)
> 
> Pressing ^U will not reset this, but pressing ^C will.

Yes, that's how it works.  I haven't understood why you think it's a
problem but I presume you're used to some other shell.

If you want to turn this feature off, use CSH_JUNKIE_HISTORY; see the
HISTORY EXPANSION section in the zshexpn manual.  Or use two !!s to
refer to the immediately preceding event.

       By  default, a history reference with no event designator refers to the
       same event as any preceding history reference on that command line;  if
       it  is the only history reference in a command, it refers to the previ‐
       ous command.  However, if the option CSH_JUNKIE_HISTORY  is  set,  then
       every  history  reference  with no event specification always refers to
       the previous command.

pws



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