Initial commit: xif

This commit is contained in:
fanyx 2024-02-28 15:13:50 +01:00
commit cbe21d0f6a
1 changed files with 38 additions and 0 deletions

38
xif Executable file
View File

@ -0,0 +1,38 @@
#!/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