zsh-users
 help / color / mirror / code / Atom feed
* populate next comand line from precmd
@ 2018-06-13  1:44 Pier Paolo Grassi
  2018-06-13  2:55 ` dana
  0 siblings, 1 reply; 3+ messages in thread
From: Pier Paolo Grassi @ 2018-06-13  1:44 UTC (permalink / raw)
  To: zsh-users

[-- Attachment #1: Type: text/plain, Size: 1011 bytes --]

hello, I was wondering if it is somehow possibile to populate the command
line within the precmd function. What I am trying to achieve is: from a
normal function (not a zle widget) I would like to set some variable, to be
read in the precmd function where it is used to populate the next command
line and also set the cursor position. I know how to do it from a widget,
but from what I know there is no way of doing this from outside a widget,
am I right?

the desidered behaviour would be:

$ special_function par par2 etc [accept-line]
output

$  special_function par par2 etc (already compiled, some params may be
modified)

I don't want to:
modify the accept-line widget
modify history so that the modified version of the line is at a press of
the up key

this is more of a "can this be done in this way?" question

thanks in advance
-- 
Pier Paolo Grassi
email: pierpaolog@gmail.com
linkedin: https://www.linkedin.com/in/pier-paolo-grassi-19300217
founder: https://www.meetup.com/it-IT/Machine-Learning-TO

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: populate next comand line from precmd
  2018-06-13  1:44 populate next comand line from precmd Pier Paolo Grassi
@ 2018-06-13  2:55 ` dana
  2018-06-13  8:10   ` Pier Paolo Grassi
  0 siblings, 1 reply; 3+ messages in thread
From: dana @ 2018-06-13  2:55 UTC (permalink / raw)
  To: zsh; +Cc: Pier Paolo Grassi

On 12 Jun 2018, at 20:44, Pier Paolo Grassi <pierpaolog@gmail.com> wrote:
>hello, I was wondering if it is somehow possibile to populate the command
>line within the precmd function. What I am trying to achieve is: from a
>normal function (not a zle widget) I would like to set some variable, to be
>read in the precmd function where it is used to populate the next command
>line and also set the cursor position.

Maybe print's -z option would help, at least partially?

  -z  Push the arguments onto the editing buffer stack, separated by spaces.

Example:

  % precmd_insert_args() {
  >   # Check some variable, whatever
  >   [[ $history[$((HISTCMD - 1))] == *bar* ]] && {
  >     print 'Saw bar'
  >     print -z : inserted args ''
  >   }
  >   return 0
  > }
  % precmd_functions+=( precmd_insert_args )
  % : foo # Condition not met
  % : bar
  Saw bar
  % : inserted args <CURSOR HERE>

I say 'partially' because i'm not sure if you can affect the cursor position
(besides inserting things in front of it, obv) from outside of a widget.

dana


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: populate next comand line from precmd
  2018-06-13  2:55 ` dana
@ 2018-06-13  8:10   ` Pier Paolo Grassi
  0 siblings, 0 replies; 3+ messages in thread
From: Pier Paolo Grassi @ 2018-06-13  8:10 UTC (permalink / raw)
  To: dana; +Cc: zsh-users

[-- Attachment #1: Type: text/plain, Size: 1693 bytes --]

thank you dana, I totally overlooked print -z, that's perfect for my use
case
in the meantime I also rediscovered about zle-line-init, which allow the
control of the next zle prompt and can get parameters from global variables.
To only allow it to act when the zle prompt is a PS1 one can set a global
variable in the precmd

Il giorno mer 13 giu 2018 alle ore 04:55 dana <dana@dana.is> ha scritto:

> On 12 Jun 2018, at 20:44, Pier Paolo Grassi <pierpaolog@gmail.com> wrote:
> >hello, I was wondering if it is somehow possibile to populate the command
> >line within the precmd function. What I am trying to achieve is: from a
> >normal function (not a zle widget) I would like to set some variable, to
> be
> >read in the precmd function where it is used to populate the next command
> >line and also set the cursor position.
>
> Maybe print's -z option would help, at least partially?
>
>   -z  Push the arguments onto the editing buffer stack, separated by
> spaces.
>
> Example:
>
>   % precmd_insert_args() {
>   >   # Check some variable, whatever
>   >   [[ $history[$((HISTCMD - 1))] == *bar* ]] && {
>   >     print 'Saw bar'
>   >     print -z : inserted args ''
>   >   }
>   >   return 0
>   > }
>   % precmd_functions+=( precmd_insert_args )
>   % : foo # Condition not met
>   % : bar
>   Saw bar
>   % : inserted args <CURSOR HERE>
>
> I say 'partially' because i'm not sure if you can affect the cursor
> position
> (besides inserting things in front of it, obv) from outside of a widget.
>
> dana
>
>

-- 
Pier Paolo Grassi
email: pierpaolog@gmail.com
linkedin: https://www.linkedin.com/in/pier-paolo-grassi-19300217
founder: https://www.meetup.com/it-IT/Machine-Learning-TO

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-06-13  8:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-13  1:44 populate next comand line from precmd Pier Paolo Grassi
2018-06-13  2:55 ` dana
2018-06-13  8:10   ` Pier Paolo Grassi

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).