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

Re: populate next comand line from precmd

On 12 Jun 2018, at 20:44, Pier Paolo Grassi <pierpaolog@xxxxxxxxx> 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.


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


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