1
0
Fork 0

[Fix #28] Add a widget to insert sudo

pull/58/head
Sorin Ionescu 13 years ago
parent 09837b259a
commit 9f8b41aaec

@ -115,6 +115,15 @@ function expand-or-complete-prefix-with-indicator() {
} }
zle -N 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' zstyle -s ':omz:editor' keymap 'keymap'
if [[ "$keymap" == (emacs|) ]]; then if [[ "$keymap" == (emacs|) ]]; then
# Use Emacs key bindings. # Use Emacs key bindings.
@ -305,5 +314,9 @@ fi
for key in "$keyinfo[Control]Q" "$keyinfo[Escape]"{q,Q}; \ for key in "$keyinfo[Control]Q" "$keyinfo[Escape]"{q,Q}; \
bindkey "$key" push-line-or-edit 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 unset key

Loading…
Cancel
Save