39 lines
716 B
Bash
Executable File
39 lines
716 B
Bash
Executable File
#!/bin/sh
|
|
|
|
[ -z "$@" ] && echo "xif: empty search term" && exit 1
|
|
|
|
filter='/^.[i*]. /d'
|
|
filter1='s/^...\? //'
|
|
filter2='s/-[^- ]* / /'
|
|
|
|
# when available, use xrs(1)
|
|
# fallback to xbps-query -Rs
|
|
XRS="xbps-query -Rs"
|
|
command -v xrs >/dev/null && XRS="xrs"
|
|
# when available, use xi(1)
|
|
# fallback to xbps-install
|
|
XI="xbps-install"
|
|
command -v xi >/dev/null && XI="xi"
|
|
|
|
install() {
|
|
sudo $XI "$@"
|
|
}
|
|
|
|
pkgs() {
|
|
$XRS "$@" | sed "$filter;$filter1;$filter2" | fzf --layout=reverse -m |\
|
|
cut -d' ' -f1 | tr '\n' ' ' | sed "s/ $//"
|
|
}
|
|
|
|
PKGS="$(pkgs "$@")"
|
|
[ -z $PKGS ] && exit 130
|
|
|
|
install -S "$PKGS"
|
|
status=$?
|
|
if [ $status -eq 16 ]; then
|
|
install -u xbps &&
|
|
install -S $(pkgs "$@")
|
|
else
|
|
exit $status
|
|
fi
|
|
|