From e4bc7029aa30f1b7597c9d22c9891a81cd5eab12 Mon Sep 17 00:00:00 2001 From: Anatoly Kopyl Date: Thu, 13 Aug 2020 02:50:20 +0300 Subject: [PATCH] Initial commit --- doas.plugin.zsh | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 doas.plugin.zsh diff --git a/doas.plugin.zsh b/doas.plugin.zsh new file mode 100644 index 0000000..27e0ca8 --- /dev/null +++ b/doas.plugin.zsh @@ -0,0 +1,32 @@ +# ------------------------------------------------------------------------------ +# Description +# ----------- +# +# doas will be inserted before the command +# +# ------------------------------------------------------------------------------ +# Authors +# ------- +# +# * Anatoly +# +# ------------------------------------------------------------------------------ + +doas-command-line() { + [[ -z $BUFFER ]] && LBUFFER="$(fc -ln -1)" + if [[ $BUFFER == doas\ * ]]; then + if [[ ${#LBUFFER} -le 4 ]]; then + RBUFFER="${BUFFER#doas }" + LBUFFER="" + else + LBUFFER="${LBUFFER#doas }" + fi + else + LBUFFER="doas $LBUFFER" + fi +} +zle -N doas-command-line +# Defined shortcut keys: [Esc] [Esc] +bindkey -M emacs '\e\e' doas-command-line +bindkey -M vicmd '\e\e' doas-command-line +bindkey -M viins '\e\e' doas-command-line