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

Re: "expanding" to copy-earlier-word

On Thu, Aug 13, 2015 at 11:24:22AM +0100, Peter Stephenson wrote:
> On Thu, 13 Aug 2015 10:57:27 +0100
> Dominik Vogt <vogt@xxxxxxxxxxxxxxxxxx> wrote:
> > I've bound ctrl-j to copy-earlier-word, so I can copy the last word
> > of the previously executed command line to the current command
> > line.  Is there a way to do the same as part of the expansion
> > process?
> Hisotry expansion allows you to select previous words, but you'll need
> to count from the left when retrieving words from the current line: you
> can use ":$" to indicate the last argument, which with !# is the
> previous argument, but "-" indicates a range, not a negative offset.
> There was some discussion about this anomaly a couple of months ago;
> it's potentially fixable with some new syntax (I've forgotten if there
> was a conclusion).
> > What I'd like to have this something like this:
> > 
> >   $ make foo
> >   $ ./<copy-earlier-word>
> ./!:$

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

According to the man page history expansion comes first, followed
by alias expansion, the result of which is not stored in the
history files, so I guess the sequence is

 1) history expansion,
 2) save command line in history,
 3) alias expansion,
 4) everything else.

If there was a way to change that order to

 1) save command line in history,
 2) alias expansion,
 3) history expansion,
 4) everything else.

one could even have history expansion in aliases:

  $ alias -g PW='!:$'
  $ make foo
  $ echo PW

(I guess the global alias wouldn't allow "echo ./PW" anyway).


Dominik ^_^  ^_^


Dominik Vogt
IBM Germany

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