Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: pre-populate zle for next command?
- X-seq: zsh-users 22860
- From: Stephen Talley <stephentalley@xxxxxxxxxxxxxxxxx>
- To: Mikael Magnusson <mikachu@xxxxxxxxx>
- Subject: Re: pre-populate zle for next command?
- Date: Thu, 31 Aug 2017 20:22:22 -0400
- Cc: Zsh Users <zsh-users@xxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=zKjflRkdTv90yQ7ukRSMr82XdXFkW5idAnzOWOd5z4g=; b=ZdADA8EpFqkDhaOzOzyaXqnyMFZECiIjDQVRZE8rL2neZ7tUNveHviDL/YHZoYwMKu VSUWgkg8hsXvDyFad9pwnb0xCY186WiVneW7x0IwtRawCgGU3OmCMUMui5j9PzAJVzmH PxstpZ44HjthHD9xPSXAXD08wccJ7Zzr8sXhnmuT4mv410GHgx89ySlqm2Y8kkBKbh+u BAGn3tIqfU0bX45w/Bmg8YTQbg8uc6GTfNBRqmszFT+q9O29oClaHeO7lgjRR+fiJdIc +MGLDKSFckdDf804qyNKJf5X43Lapx6wovhCRa/xGHhdND+OlydKnmU4VzFPazsE7VPW cTYQ==
- In-reply-to: <CAHYJk3T5SsaTOwh2XWc-QWtW1XADqXP5nuO=+94KptqZPLogQA@mail.gmail.com>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <CAMWw+bzYVfEL-Jx7VTmj-nboZWnLGL5gX1e3QaY03cULmHyADw@mail.gmail.com> <CAHYJk3T5SsaTOwh2XWc-QWtW1XADqXP5nuO=+94KptqZPLogQA@mail.gmail.com>
- Sender: stephentalley@xxxxxxxxx
Oh, excellent. I knew there had to be an easy way to do this.
Thank you!
On 31 August 2017 at 15:33, Mikael Magnusson <mikachu@xxxxxxxxx> wrote:
> On Thu, Aug 31, 2017 at 7:38 PM, Stephen Talley
> <stephentalley@xxxxxxxxxxxxxxxxx> wrote:
> > Is there any way for a command to pre-populate the the zle for the next
> > command?
> >
> > Suppose I have, for example, a zsh function "buildcmd" that produces a
> > command line (based on supplied arguments, say) that the user would then
> be
> > able to edit in the zle before hitting enter to accept the line and
> execute
> > it. The flow would be:
> >
> > % buildcmd --my --args<enter>
> > % <output_from_buildcmd>
> >
> > I know I could just do:
> >
> > % `buildcmd --my --args`<tab>
> >
> > to achieve the same thing, but it's a bit more tedious than I'd like.
> >
> > Ideally there'd be some hook (precmd? accept-line?) that could check a
> > variable and pre-populate the zle:
> >
> > buildcmd() {
> > zle_prepopulate="some command to edit"
> > }
> >
> > precmd() {
> > if [ -n "$zle_prepopulate" ]
> > then
> > zle -U "$zle_prepopulate"
> > fi
> > }
> >
> > ...but of course this doesn't quite work because the call to zle is not
> in
> > the context of a widget.
> >
> > Is there a way?
>
> You can use print -z to push any string you like on the zle editor
> stack, which effectively does what you want. (Ie, it is popped when
> the next command line is to be entered, which is immediately). There's
> no need to involve precmd or any hook, you can just call print -z
> directly from your function.
>
> --
> Mikael Magnusson
>
Messages sorted by:
Reverse Date,
Date,
Thread,
Author