Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [PATCH] Add execute-command() widget function (was Re: [RFC][PATCH] Add change-directory() widget function)
On Thu, Apr 22, 2021 at 3:55 AM Marlon Richert <marlon.richert@xxxxxxxxx> wrote:
>
> If I would use push-input instead of push-line-or-edit, the buffer would not get restored immediately after using the widget. You’d end up with a blank command line instead. I want it to work the same from PS2 as it does from PS1.
I see. (Also, I forgot that push-input is implemented via
push-line-or-edit, not the other way around.)
Then how about:
execute-command() {
local finish="zle .reset-prompt"
case $CONTEXT in
(cont) finish="zle .push-line-or-edit"
;&
(start)
print -S "${${(q-)@}}"
eval "${(q-)@}"
;;
(*) return 75
;;
esac
eval "$finish"
}
> Setting PUSHD_MINUS in the example guarantees that it will work out of the box for novice users. (More advanced users, I’m sure, will be able to figure out how to modify it to suit their needs.)
As I mentioned, by turning this into a generic "execute-command"
you've made it the responsibility of the caller to pass the right
thing. The question then is how to write the examples.
Instead of
setopt autopushd pushdminus pushdsilent
cd-backward() { execute-command -- 'pushd -1' }
It should be similar to
cd-backward() {
setopt localoptions autopushd pushdminus pushdsilent
execute-command -- pushd -1
}
(I removed the quotes around «pushd -1» to correspond to my use of
${(q-)@} above.)
Messages sorted by:
Reverse Date,
Date,
Thread,
Author