[pacman] cleanup privileged vs unprivileged

* moves check for yaourt into the other zpacman_frontend checks
* remove hardcoded sudo vs non-sudo; uses zpacman_frontend[_priv]
instead.
  * these vars are set in the zpacman_frontend value sanity check.
  * for values != yaourt, prepend sudo for zpacman_frontend_priv
This commit is contained in:
Matt Hamilton 2016-02-06 15:17:37 -05:00
parent 0e19c3d277
commit 7874b97bf1
1 changed files with 25 additions and 20 deletions

View File

@ -14,23 +14,29 @@ if (( ! ${+commands[pacman]} )); then
return 1
fi
local zpacman_frontend_priv helper
if (( ! ${+zpacman_frontend} )); then
zpacman_frontend='pacman'
zpacman_frontend_priv='sudo pacman'
elif (( ! ${+commands[${zpacman_frontend}]} )); then
print "pacman frontend \"${zpacman_frontend}\" is invalid or not installed. Reverting to \"pacman\".
you can fix this error by editing the 'zpacman_frontend' variable in your .zimrc" >&2
You can fix this error by editing the 'zpacman_frontend' variable in your .zimrc" >&2
zpacman_frontend='pacman'
zpacman_frontend_priv='sudo pacman'
elif [[ ${zpacman_frontend} == "yaourt" ]]; then
# yaourt handles SUID itself
zpacman_frontend_priv="${zpacman_frontend}"
else
zpacman_frontend_priv="sudo ${zpacman_frontend}"
fi
if [[ ${zpacman_frontend} != "yaourt" ]]; then
zpacman_frontend="sudo ${zpacman_frontend}"
fi
#
# General
#
alias pac=${zpacman_frontend#* }
alias pac=${zpacman_frontend}
#
# Build
@ -46,16 +52,16 @@ alias pacb='makepkg -sci'
#NOTE: Installing/upgrading individual packages is NOT supported. Sync and upgrade ALL on install.
# install, sync, and upgrade packages
alias paci="${zpacman_frontend} -Syu"
alias paci="${zpacman_frontend_priv} -Syu"
# install, sync, and upgrade packages (forcibly refresh package lists)
alias pacu="${zpacman_frontend} -Syyu"
alias pacu="${zpacman_frontend_priv} -Syyu"
# install packages by filename
alias pacU="sudo pacman -U"
alias pacU="${zpacman_frontend_priv} -U"
# install all packages in current directory
alias pacd="sudo pacman -U *.pkg.tar.xz"
alias pacd="${zpacman_frontend_priv} -U *.pkg.tar.xz"
#
@ -63,10 +69,10 @@ alias pacd="sudo pacman -U *.pkg.tar.xz"
#
# remove package and unneeded dependencies
alias pacr='sudo pacman -R'
alias pacr="${zpacman_frontend_priv} -R"
# remove package, unneeded dependencies, and configuration files
alias pacrm='sudo pacman -Rns'
alias pacrm="${zpacman_frontend_priv} -Rns"
#
@ -74,10 +80,10 @@ alias pacrm='sudo pacman -Rns'
#
# query package information from the remote repository
alias pacq='pacman -Si'
alias pacq="${zpacman_frontend} -Si"
# query package information from the local repository
alias pacQ='pacman -Qi'
alias pacQ="${zpacman_frontend} -Qi"
#
@ -85,10 +91,10 @@ alias pacQ='pacman -Qi'
#
# search for package in the remote repository
alias pacs='pacman -Ss'
alias pacs="${zpacman_frontend} -Ss"
# search for the package in the local repository
alias pacS='pacman -Qs'
alias pacS="${zpacman_frontend} -Qs"
#
@ -96,10 +102,10 @@ alias pacS='pacman -Qs'
#
# list orphan packages
alias pacol='pacman -Qdt'
alias pacol="${zpacman_frontend} -Qdt"
# remove orphan packages
alias pacor='sudo pacman -Rns $(pacman -Qtdq)'
alias pacor="${zpacman_frontend_priv} -Rns $(pacman -Qtdq)"
#
@ -107,10 +113,10 @@ alias pacor='sudo pacman -Rns $(pacman -Qtdq)'
#
# list all files that belong to a package
alias pacown='pacman -Ql'
alias pacown="${zpacman_frontend} -Ql"
# show package(s) owning the specified file
alias pacblame='pacman -Qo'
alias pacblame="${zpacman_frontend} -Qo"
#
# Helpers
@ -124,4 +130,3 @@ for helper ( ${zpacman_helper[@]} ); do
print "no such helper script \"helper_${helper}.zsh\"" >&2
fi
done
unset helper