forked from jedahan/kiss-find
-
Notifications
You must be signed in to change notification settings - Fork 1
/
kiss-find.sh
executable file
·72 lines (61 loc) · 1.64 KB
/
kiss-find.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/sh -e
# Search for packages across every known repository
# kiss-find version 2.3
DB_PATH="${XDG_CACHE_HOME:-${HOME}/.cache}"/kiss-find/db.csv
UPDATE_URL="https://aabacchus.github.io/kiss-find/db.csv"
help() {
printf "usage: kiss-find [-u] <query>\n"
printf "search for <query> in packages across every known repository\n"
printf "\t-u\tUpdate package database\n"
}
update() {
# taken from kiss
cmd_get=${KISS_GET:-"$(
command -v aria2c ||
command -v axel ||
command -v curl ||
command -v wget ||
command -v wget2
)"} || {
printf ":: No download utility found (aria2c, axel, curl, wget, wget2)\n" >&2
exit 1
}
tmpfile="${KISS_TMPDIR:-/tmp}/kiss-find-db.csv"
rm -f "$tmpfile"
set -- "$tmpfile" "$UPDATE_URL"
# Set the arguments based on found download utility.
case ${cmd_get##*/} in
aria2c|axel) set -- -o "$@" ;;
curl) set -- -fLo "$@" ;;
wget|wget2) set -- -O "$@" ;;
esac
"$cmd_get" "$@" || {
printf ":: Failed to download\n" >&2
rm -f "$tmpfile"
exit 1
}
mv -f "$tmpfile" "$DB_PATH"
printf ":: Update done\n" >&2
}
mkdir -p "$(dirname "$DB_PATH")"
case "$1" in
"" | "-h"*)
help
exit
;;
"-u"*)
update
shift
[ "$1" = "" ] && exit
;;
esac
if [ ! -f "$DB_PATH" ]; then
printf ":: Please run 'kiss-find -u' to download the latest database\n" >&2
exit 1
fi
${KISS_FIND_GREP:-grep} "^[^,]*$1[^,]*," "$DB_PATH" | sort |
if [ -t 1 ] && command -v column >/dev/null 2>&1; then
column -t -s',';
else
cat;
fi