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

Re: "expanding" to copy-earlier-word



On Thu, 13 Aug 2015 12:45:55 +0100
Dominik Vogt <vogt@xxxxxxxxxxxxxxxxxx> wrote:
> Sort of works for me after "setopt histexpand".  Unfortunately, is
> saves "./foo" in the history instead of "./!:$".  It looks like
> there's no option to have the unexpanded string stored in the
> history?

No, that's not how history works.  It's hard-wired to work only
immediately on input, before anything else happens, and pass the
processed output to the rest of the shell.  It's not possible to
get it to behave any other way.

You can do this...

% zmodload zsh/parameter
% echo foo; print ./${${(z)history[$HISTCMD]}[-4]
foo
./foo

in which:

$history[$HISTCMD] is the full current history line.

(z) splits it into words using shell syntax.  ";" is a word here, too.

Hence "foo" is the fourth word from the right, [-4].

I would have thought a function with a single argument was much simpler...

pws



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