From: Mikael Magnusson <mikachu@gmail.com>
To: Stephen Talley <stephentalley@nerdysoftware.com>
Cc: Zsh Users <zsh-users@zsh.org>
Subject: Re: pre-populate zle for next command?
Date: Thu, 31 Aug 2017 21:33:54 +0200 [thread overview]
Message-ID: <CAHYJk3T5SsaTOwh2XWc-QWtW1XADqXP5nuO=+94KptqZPLogQA@mail.gmail.com> (raw)
In-Reply-To: <CAMWw+bzYVfEL-Jx7VTmj-nboZWnLGL5gX1e3QaY03cULmHyADw@mail.gmail.com>
On Thu, Aug 31, 2017 at 7:38 PM, Stephen Talley
<stephentalley@nerdysoftware.com> 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
next prev parent reply other threads:[~2017-08-31 19:34 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-31 17:38 Stephen Talley
2017-08-31 19:33 ` Mikael Magnusson [this message]
2017-09-01 0:22 ` Stephen Talley
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAHYJk3T5SsaTOwh2XWc-QWtW1XADqXP5nuO=+94KptqZPLogQA@mail.gmail.com' \
--to=mikachu@gmail.com \
--cc=stephentalley@nerdysoftware.com \
--cc=zsh-users@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).