1
0
mirror of https://github.com/frebib/dotfiles.git synced 2024-06-14 12:57:23 +00:00

zsh: improve <ESC><ESC> sudo action with vim

This commit is contained in:
Joe Groocock 2018-07-30 09:30:03 +01:00
parent 815da41076
commit 7f8c8eccb3
Signed by: frebib
GPG Key ID: E0B16BEACFBB6A86
2 changed files with 5 additions and 7 deletions

View File

@ -4,14 +4,11 @@ sudo-command-line() {
[[ -z $BUFFER ]] && zle up-history
if [[ $BUFFER == sudo\ * ]]; then
LBUFFER="${LBUFFER#sudo }"
elif [[ $BUFFER == $EDITOR\ * ]] || [[ $BUFFER == vi\ * ]]; then
LBUFFER="${LBUFFER#$EDITOR }"
LBUFFER="${LBUFFER#vi }"
LBUFFER="svi $LBUFFER"
elif [[ $BUFFER == sudoedit\ * ]] || [[ $BUFFER == svi\ * ]]; then
elif [[ $BUFFER == $EDITOR\ * ]] || [[ $BUFFER == vi\ * ]] || [[ $BUFFER == vim\ * ]]; then
LBUFFER="s$LBUFFER"
elif [[ $BUFFER == sudoedit\ * ]] || [[ $BUFFER == svi\ * ]]|| [[ $BUFFER == svim\ * ]]; then
LBUFFER="${LBUFFER#sudoedit }"
LBUFFER="${LBUFFER#svi }"
LBUFFER="$EDITOR $LBUFFER"
LBUFFER="${LBUFFER#s}"
else
LBUFFER="sudo $LBUFFER"
fi

View File

@ -40,6 +40,7 @@ alias -g CLIP="| xclip -i -selection primary -f | xclip -i -selection clipboard"
calc() { bc -l <<< "$@"; }
alias svi=sudoedit
alias svim=sudoedit
# This will enable us to use aliases in sudo.
# (If alias finishes with a space or tab, the shell will check if the next command is also aliased.)
# Source: https://github.com/mayah/home/blob/master/.zsh/zshrc.d/alias.zsh