[Fix #28] Add a widget to insert sudo
This commit is contained in:
parent
09837b259a
commit
9f8b41aaec
13
keyboard.zsh
13
keyboard.zsh
|
@ -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…
Reference in a new issue