diff --git a/init.zsh b/init.zsh index 7a3720d..b9528f1 100644 --- a/init.zsh +++ b/init.zsh @@ -55,8 +55,17 @@ alias cd..="cd .." # Make xargs, sudo, etc. understand aliases alias xargs='xargs ' -cmd_exists sudo && alias sudo='sudo ' -cmd_exists doas && alias doas='doas ' +if cmd_exists doas; then + __zsh_sudo_cmd=doas + alias sudo='doas ' + alias doas='doas ' + alias sudoedit="doas $EDITOR " + alias se="doas $EDITOR " +else + __zsh_sudo_cmd=sudo + alias sudo='sudo ' + alias se='sudoedit ' +fi # Emacs and Neovim stuff if [[ -v NVIM ]]; then @@ -92,7 +101,6 @@ else alias d=dired fi export VISUAL="${EDITOR}" -alias se=sudoedit # Safer file functions alias cp="cp -i" @@ -170,16 +178,10 @@ alias gt="git status" # Sudo last line with sudo-command-line() { [[ -z $BUFFER ]] && zle up-history - if [[ $BUFFER == sudo\ * ]]; then - LBUFFER="${LBUFFER#sudo }" - elif [[ $BUFFER == $EDITOR\ * ]]; then - LBUFFER="${LBUFFER#$EDITOR }" - LBUFFER="sudoedit $LBUFFER" - elif [[ $BUFFER == sudoedit\ * ]]; then - LBUFFER="${LBUFFER#sudoedit }" - LBUFFER="$EDITOR $LBUFFER" + if [[ $BUFFER == ${__zsh_sudo_cmd}\ * ]]; then + LBUFFER="${LBUFFER#${__zsh_sudo_cmd} }" else - LBUFFER="sudo $LBUFFER" + LBUFFER="${__zsh_sudo_cmd} $LBUFFER" fi } zle -N sudo-command-line