From 443005d1f88d01bd394c2ca1ed62a039a5597788 Mon Sep 17 00:00:00 2001 From: Alex Poslavsky Date: Mon, 23 May 2016 08:57:31 +0300 Subject: [PATCH] [input] add doas/sudo insert bind --- modules/utility/init.zsh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/modules/utility/init.zsh b/modules/utility/init.zsh index 9fb20aa..61cd35d 100644 --- a/modules/utility/init.zsh +++ b/modules/utility/init.zsh @@ -118,3 +118,20 @@ fi mkcd() { [[ -n ${1} ]] && mkdir -p ${1} && builtin cd ${1} } + +# Inserts 'doas ' or 'sudo ' at the beginning of a line. +function prepend-sudoas { + if [[ "$BUFFER" != (doas|su(do|))\ * ]]; then + if [[ $OSTYPE == openbsd* ]]; then + BUFFER="doas $BUFFER" + else + BUFFER="sudo $BUFFER" + fi + (( CURSOR += 5 )) + fi +} +zle -N prepend-sudoas + +# Defined shortcut keys: [Esc] [Esc] +bindkey "\e!" prepend-sudoas +