From 9f8b41aaec63076d25b41b41c85c9244576c2cdb Mon Sep 17 00:00:00 2001 From: Sorin Ionescu Date: Sun, 18 Mar 2012 19:20:00 -0400 Subject: [PATCH] [Fix #28] Add a widget to insert sudo --- keyboard.zsh | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/keyboard.zsh b/keyboard.zsh index 52478ef..36dc845 100644 --- a/keyboard.zsh +++ b/keyboard.zsh @@ -115,6 +115,15 @@ function expand-or-complete-prefix-with-indicator() { } zle -N expand-or-complete-prefix-with-indicator +# Inserts 'sudo ' at the beginning of the line. +function prepend-sudo() { + if [[ "$BUFFER" != su(do|)\ * ]]; then + BUFFER="sudo $BUFFER" + (( CURSOR += 5 )) + fi +} +zle -N prepend-sudo + zstyle -s ':omz:editor' keymap 'keymap' if [[ "$keymap" == (emacs|) ]]; then # Use Emacs key bindings. @@ -305,5 +314,9 @@ fi for key in "$keyinfo[Control]Q" "$keyinfo[Escape]"{q,Q}; \ bindkey "$key" push-line-or-edit +# Insert 'sudo ' at the beginning of the line. +[[ -n "$keyinfo[Control]" ]] && \ + bindkey "$keyinfo[Control]X$keyinfo[Control]S" prepend-sudo + unset key