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

Re: Howto to print ENTER to zle-buffer?



On Dec 13,  8:29pm, Andy Spiegl wrote:
} Subject: Re: Howto to print ENTER to zle-buffer?
}
} > Given this -- and assuming you can target zsh-5.3 -- I'd go with:
} I'm still stuck with 5.2.  Guess I have to wait a while then. :-(

No, it can still be done; you'll just have to be sure that your
zle-line-init widget doesn't conflict with one the user already has.

Actually if you grab Functions/Misc/add-zle-hook-widget from 5.3 and
make it part of your session manager, it should work in 5.2.

} You define the function "session-startup"

Which I typo'd, I left out the () between the function name and the
open brace ...

} which is then hooked
} to zle such that it is run after initialization?  How does it show
} up in the zle buffer then?  No "print -z" anymore?

I won't show up in the ZLE buffer, instead it will just execute at
the time zle starts up.  I don't know why you'd need it to appear in
the buffer if it's just going to be accept-line'd immediately, but
you can do that like this:

session-startup() {
  zle -U $'command-to-run args\n'
  add-zle-hook-widget -d line-init $WIDGET
}

To "backport" that to 5.2 without add-zle-hook-widget:

zle-line-init() {
  if [[ -n $functions[session-startup] ]]
  then
    session-startup
    unfunction session-startup
  fi
  # Do whatever the user's zle-line-init did
}
zle -N zle-line-init

session-startup() {
  zle -U $'command-to-run args\n'
}



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