Browse Source

[Fix #28] Add a widget to insert sudo

master
Sorin Ionescu 12 years ago
parent
commit
9f8b41aaec
  1. 13
      keyboard.zsh

13
keyboard.zsh

@ -115,6 +115,15 @@ function expand-or-complete-prefix-with-indicator() { @@ -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 @@ -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

Loading…
Cancel
Save