55 lines
1.0 KiB
Bash
Executable File
55 lines
1.0 KiB
Bash
Executable File
#!/bin/sh
|
|
# vim: set ts=4 sw=4 et:
|
|
|
|
command -v fzf >/dev/null || sudo xbps-install -S fzf
|
|
|
|
[ -z "$*" ] && echo "xif: empty search term" && exit 1
|
|
|
|
filter='/^.[i*]. /d'
|
|
filter1='s/^...\? //'
|
|
filter2='s/-[^- ]* / /'
|
|
|
|
XRS="xbps-query -Rs"
|
|
command -v xrs >/dev/null && XRS="xrs"
|
|
XI="xbps-install"
|
|
command -v xi >/dev/null && XI="xi"
|
|
|
|
which_sudo() {
|
|
if [ "$(id -u)" = "0" ]; then
|
|
return
|
|
elif command -v sudo >/dev/null && sudo -l | grep -q -e ' ALL$' -e xbps-install; then
|
|
echo sudo
|
|
elif command -v doas >/dev/null && [ -f /etc/doas.conf ]; then
|
|
echo doas
|
|
else
|
|
echo su
|
|
fi
|
|
}
|
|
|
|
install() {
|
|
echo "xif: $SUDO $XI $@"
|
|
echo
|
|
$SUDO $XI $@
|
|
}
|
|
|
|
pkgs() {
|
|
echo $@ | tr ' ' '\n' | xargs -i $XRS {} | uniq |\
|
|
sed "$filter;$filter1;$filter2" | fzf --layout=reverse -m |\
|
|
cut -d' ' -f1 | tr '\n' ' ' | sed "s/ $//"
|
|
}
|
|
|
|
PKGS="$(pkgs $@)"
|
|
[ -z "$PKGS" ] && exit 130
|
|
|
|
SUDO=$(which_sudo)
|
|
install -S $PKGS
|
|
|
|
status=$?
|
|
if [ $status -eq 16 ]; then
|
|
install -u xbps &&
|
|
install -S $PKGS
|
|
else
|
|
exit $status
|
|
fi
|
|
|