Create xr script - xbps-remove

This commit is contained in:
fanyx 2021-09-13 09:49:55 +02:00
parent b6906e65a9
commit 2638f4a240
3 changed files with 27 additions and 2 deletions

25
.local/bin/xr Executable file
View File

@ -0,0 +1,25 @@
#!/bin/sh
# xr PKGS... - like xbps-remove -o, but take sudo/su into account
which_sudo() {
if command -v sudo >/dev/null && sudo -l | grep -q -e ' ALL$' -e xbps-remove; then
echo sudo
elif command -v doas >/dev/null && [ -f /etc/doas.conf ]; then
echo doas
elif [ "$(id -u)" != 0 ]; then
echo su
fi
}
do_remove() {
if [ "$SUDO" = su ]; then
su root -c 'xbps-remove "$@"' -- sh "$@"
else
$SUDO xbps-remove "$@"
fi
}
SUDO=$(which_sudo)
do_remove -R "$@"
exit $?

View File

@ -16,6 +16,4 @@ alias xqm="xq -m"
alias xql="xq -l"
alias xqq="xql | grep ${1}"
# xbps-remove
alias xr="doas xbps-remove -R"
alias xcln="xr -o"

View File

@ -7,6 +7,8 @@
# If not running interactively, don't do anything
[[ $- != *i* ]] && return
PATH=~/.local/bin:$PATH
#################################
# - bash_aliases
# - bash-completion