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

Re: retrieving the results of last command?

Mikael Magnusson wrote:
> On 5/20/05, Peter Stephenson <pws@xxxxxxx> wrote:
> > insert-last-command-output() {
> >   LBUFFER+=3D"$(eval $history[$((HISTCMD-1))])"
> > }

> Hello,
> Is there a way to ask for confirmation here? It's not always history
> contains what you expect, for example if you share history and just
> ran rm -rf . in another terminal, and press this bind you might not be
> so happy with the outcome. Ie something like
> zsh: are you sure you want to run $history[$((HISTCMD-1))] again? [yn]
> Is the read builtin what i want? I never quite got the hang of that one.

With 4.2, the best way of prompting from within a command line is to use
the supplied function read-from-minibuffer.  Something like this:

insert-last-command-output() {
  local hist=$history[$((HISTCMD-1))] REPLY

  autoload -U read-from-minibuffer
  read-from-minibuffer -k1 "Do you want to execute
again y/[n]? " || [[ $REPLY = [yY]* ]] || return 1

  LBUFFER+="$(eval $hist)"

Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070

This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.


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