# Lets you implement widgets that can execute arbitrary commands without losing # the current command line, in a fashion similar to the 'run-help' and # 'which-command' widgets. See the manual for more details. zmodload -F zsh/zutil b:zparseopts local -A opts zparseopts -D -A opts - e s v: local -a err zle || err+=( "${0}: can only be called from zle widgets" ) (( # )) || err+=( "${0}: not enough arguments" ) if [[ -n $err ]]; then print -lu2 -- $err[@] \ $'Usage: execute-commands [ ] [--] ... Execute commands from zle widget, without mangling prompt or buffer. Options: -e echo commands before executing -s save commands to history -v store last command\'s exit status in param ' return 1 fi case $CONTEXT in ( cont | start ) print -rz -- "$PREBUFFER$BUFFER" # Push all lines to buffer stack. [[ -v opts[-e] ]] && BUFFER="${(F)@}" # Echo commands to buffer. [[ -v opts[-s] ]] && print -rS -- "${(F)@}" # Save commands to history. eval "${(F)@}" # Execute commands. local -i ret=$? [[ -v opts[-v] ]] && eval "$opts[-v]=$ret" # Store exit status. ;; ( * ) return 75 # EX_TEMPFAIL; see `man 3 sysexits`. ;; esac zle .send-break