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

Re: retrieving the results of last command?



On 5/20/05, Peter Stephenson <pws@xxxxxxx> wrote:
> 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
>   $hist
> again y/[n]? " || [[ $REPLY = [yY]* ]] || return 1
> 
>   LBUFFER+="$(eval $hist)"
> }

Thanks, that works fine (i assume the first || should be a && though).

(ps, sorry about the ccing on the last mail, gmail still does the
wrong thing when replying to a mailing lists and i didn't quite fix it
right.)
-- 
Mikael Magnusson



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