Use env_keep+=HOME var for sudo

This commit is contained in:
Jeremy Gardais 2018-04-19 18:59:24 +02:00
parent bcfc4c5bb9
commit be91605bfe
1 changed files with 11 additions and 17 deletions

28
zshrc
View File

@ -49,10 +49,17 @@ else
alias lr='ls -R | grep ":$" | sed -e '\''s/:$//'\'' -e '\''s/[^-][^\/]*\//--/g'\'' -e '\''s/^/ /'\'' -e '\''s/-/|/'\''' alias lr='ls -R | grep ":$" | sed -e '\''s/:$//'\'' -e '\''s/[^-][^\/]*\//--/g'\'' -e '\''s/^/ /'\'' -e '\''s/-/|/'\'''
fi fi
# Faire en sorte que sudo puisse également utiliser les alias! (c'est l'espace qui fait toute la différence) # sudo
# `man zshall` partie Aliasing: "If the text ends with a space, the next word in the shell input is treated as though it were in command position for ## Please consider using "Defaults env_keep+=HOME" configuration in sudoers {{{
# purposes of alias expansion. " ### This is Ubuntu default behaviour.
### This will allow to share user's homedir/dotfiles with root throught sudo commands
## }}}
## Ensure sudo can use aliases (end whitespace) {{{
### `man zshall` partie Aliasing: "If the text ends with a space, the next word in the shell input is treated as though it were in command position for
### purposes of alias expansion. "
alias s='sudo ' alias s='sudo '
## }}}
## sudo aliases {{{
if [ ${USER} != "root" ]; then if [ ${USER} != "root" ]; then
alias sc='sudo systemctl ' alias sc='sudo systemctl '
alias sd='sudo docker' alias sd='sudo docker'
@ -72,6 +79,7 @@ else
alias vi='vi -S ~/.vim/vimrc ' alias vi='vi -S ~/.vim/vimrc '
alias sv='vi -S ~/.vim/vimrc ' alias sv='vi -S ~/.vim/vimrc '
fi fi
## }}}
# Raccourcis pour cat # Raccourcis pour cat
alias ca='cat -n' alias ca='cat -n'
@ -405,20 +413,6 @@ alias stat_sys="echo ' ' && uname -a && echo ' '&& uptime &&echo ' '&& df && ech
#####FONCTIONS #####FONCTIONS
###################################### ######################################
# Sudo
function sudo() {
if [ ${USER} = "root" ]; then
"${@}"
else
if alias "${1}" &> /dev/null ; then
#$(type "$1" | sed -E 's/^.*`(.*).$/\1/') "${@:2}"
command -v "${1}" | \grep -o -P "(?<=\').*(?=')" | xargs sudo -E env "PATH=$PATH"
else
command sudo -E env "PATH=$PATH" "$@"
fi
fi
}
# SSH # SSH
function clearsshkey() { function clearsshkey() {
sed -i "${1}d" ~/.ssh/known_hosts sed -i "${1}d" ~/.ssh/known_hosts