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 # Make xargs, sudo, etc. understand aliases
alias xargs='xargs ' alias xargs='xargs '
cmd_exists sudo && alias sudo='sudo ' if cmd_exists doas; then
cmd_exists doas && alias doas='doas ' __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 # Emacs and Neovim stuff
if [[ -v NVIM ]]; then if [[ -v NVIM ]]; then
@ -92,7 +101,6 @@ else
alias d=dired alias d=dired
fi fi
export VISUAL="${EDITOR}" export VISUAL="${EDITOR}"
alias se=sudoedit
# Safer file functions # Safer file functions
alias cp="cp -i" alias cp="cp -i"
@ -170,16 +178,10 @@ alias gt="git status"
# Sudo last line with <Esc><Esc> # Sudo last line with <Esc><Esc>
sudo-command-line() { sudo-command-line() {
[[ -z $BUFFER ]] && zle up-history [[ -z $BUFFER ]] && zle up-history
if [[ $BUFFER == sudo\ * ]]; then if [[ $BUFFER == ${__zsh_sudo_cmd}\ * ]]; then
LBUFFER="${LBUFFER#sudo }" LBUFFER="${LBUFFER#${__zsh_sudo_cmd} }"
elif [[ $BUFFER == $EDITOR\ * ]]; then
LBUFFER="${LBUFFER#$EDITOR }"
LBUFFER="sudoedit $LBUFFER"
elif [[ $BUFFER == sudoedit\ * ]]; then
LBUFFER="${LBUFFER#sudoedit }"
LBUFFER="$EDITOR $LBUFFER"
else else
LBUFFER="sudo $LBUFFER" LBUFFER="${__zsh_sudo_cmd} $LBUFFER"
fi fi
} }
zle -N sudo-command-line zle -N sudo-command-line