From 2638f4a24093d65edc3df952c13a13013c9dd2d8 Mon Sep 17 00:00:00 2001 From: fanyx Date: Mon, 13 Sep 2021 09:49:55 +0200 Subject: [PATCH] Create xr script - xbps-remove --- .local/bin/xr | 25 +++++++++++++++++++++++++ .void.bash_aliases | 2 -- .void.bashrc | 2 ++ 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100755 .local/bin/xr diff --git a/.local/bin/xr b/.local/bin/xr new file mode 100755 index 0000000..5b30c0b --- /dev/null +++ b/.local/bin/xr @@ -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 $? diff --git a/.void.bash_aliases b/.void.bash_aliases index 38880e9..8c9d9ae 100644 --- a/.void.bash_aliases +++ b/.void.bash_aliases @@ -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" diff --git a/.void.bashrc b/.void.bashrc index 19dabc6..d73c2ad 100644 --- a/.void.bashrc +++ b/.void.bashrc @@ -7,6 +7,8 @@ # If not running interactively, don't do anything [[ $- != *i* ]] && return +PATH=~/.local/bin:$PATH + ################################# # - bash_aliases # - bash-completion