Change sudo stuff

This commit is contained in:
Alexander Rosenberg 2024-03-27 02:54:07 -07:00
parent 99c08d92be
commit 5149ce5797
Signed by: Zander671
GPG Key ID: 5FD0394ADBD72730

View File

@ -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 <Esc><Esc>
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