diff options
author | Gordon GECOS <u@adam> | 2024-07-29 18:08:03 -0400 |
---|---|---|
committer | Gordon GECOS <u@adam> | 2024-07-29 18:08:03 -0400 |
commit | ab6be19690c573fdb112977edcfec8cdbfb6e775 (patch) | |
tree | 72e71fa5053385e1758aa4d265775d97c3101df9 /search | |
parent | 35b233aa6473b83e1385f247a79bb71b5ff08ef0 (diff) |
search: features & fixes
Diffstat (limited to 'search')
-rwxr-xr-x | search | 67 |
1 files changed, 61 insertions, 6 deletions
@@ -1,5 +1,6 @@ | |||
1 | #!/bin/bash | 1 | #!/bin/bash |
2 | set -e | 2 | set -e |
3 | set -f | ||
3 | set -o pipefail | 4 | set -o pipefail |
4 | shopt -s lastpipe | 5 | shopt -s lastpipe |
5 | 6 | ||
@@ -24,6 +25,30 @@ search_url() | |||
24 | echo https://search.f-droid.org/'?q='"$q"${p:+'&page='$p}'&lang='${lang:-en} | 25 | echo https://search.f-droid.org/'?q='"$q"${p:+'&page='$p}'&lang='${lang:-en} |
25 | } | 26 | } |
26 | 27 | ||
28 | showpage() | ||
29 | { | ||
30 | ( | ||
31 | out=$(mktemp) | ||
32 | trap 'rm -f "$out"' EXIT | ||
33 | # wget -q "$1" -c -O "$out" | ||
34 | curl --fail -s -S -L "$1" -o "$out" | ||
35 | show_pkg "$out" | less -E | ||
36 | rm -f "$out" | ||
37 | trap - EXIT | ||
38 | ) | ||
39 | } | ||
40 | |||
41 | show_pkg() | ||
42 | { | ||
43 | for x in name summary description | ||
44 | do | ||
45 | hxextract .package-$x "$1" | | ||
46 | w3m -T text/html | | ||
47 | sed -e '/^$/d' | ||
48 | echo | ||
49 | done | ||
50 | } | ||
51 | |||
27 | search() | 52 | search() |
28 | { | 53 | { |
29 | page=${page:-1} | 54 | page=${page:-1} |
@@ -43,6 +68,8 @@ search() | |||
43 | hxclean < "$out" | | 68 | hxclean < "$out" | |
44 | hxselect -s '\n' span.package-summary | | 69 | hxselect -s '\n' span.package-summary | |
45 | mapfile -t summary | 70 | mapfile -t summary |
71 | rm -f "$out" | ||
72 | trap - EXIT | ||
46 | [ ${#href[@]} = ${#name[@]} ] | 73 | [ ${#href[@]} = ${#name[@]} ] |
47 | [ ${#href[@]} = ${#summary[@]} ] | 74 | [ ${#href[@]} = ${#summary[@]} ] |
48 | OPTIONS=() | 75 | OPTIONS=() |
@@ -59,7 +86,12 @@ search() | |||
59 | s=$(w3m -T text/html <<<"$s") | 86 | s=$(w3m -T text/html <<<"$s") |
60 | OPTIONS+=("$(printf "%40s: %s" "$n" "$s")") | 87 | OPTIONS+=("$(printf "%40s: %s" "$n" "$s")") |
61 | done | 88 | done |
62 | PS3='Choose <number> to install, [n]ext, [p]revious, or m<number> for [m]ore> ' | 89 | if [ ${#OPTIONS[@]} = 0 ] |
90 | then | ||
91 | echo "No results for ${@@Q}" >&2 | ||
92 | return | ||
93 | fi | ||
94 | PS3='Choose <number> to install, s<number> to [s]how, or [n]ext/[p]revious page> ' | ||
63 | select i in "${OPTIONS[@]}" | 95 | select i in "${OPTIONS[@]}" |
64 | do | 96 | do |
65 | if [ "$i" ] | 97 | if [ "$i" ] |
@@ -67,11 +99,18 @@ search() | |||
67 | i=$((REPLY - 1)) | 99 | i=$((REPLY - 1)) |
68 | ( | 100 | ( |
69 | set -x | 101 | set -x |
70 | mkdir repo/"${href[$i]##*/}" | 102 | mkdir -p repo/"${href[$i]##*/}" |
71 | ) | 103 | ) |
72 | continue | 104 | continue |
73 | fi | 105 | fi |
74 | case "${REPLY@L}" in | 106 | case "${REPLY@L}" in |
107 | q ) | ||
108 | return | ||
109 | ;; | ||
110 | q* ) | ||
111 | page=1 search ${REPLY#?} | ||
112 | return | ||
113 | ;; | ||
75 | n ) | 114 | n ) |
76 | let ++page | 115 | let ++page |
77 | search "$@" | 116 | search "$@" |
@@ -82,19 +121,35 @@ search() | |||
82 | search "$@" | 121 | search "$@" |
83 | return | 122 | return |
84 | ;; | 123 | ;; |
85 | m*[^0-9\ ] ) | 124 | s*[^0-9\ ] ) |
86 | continue | 125 | continue |
87 | ;; | 126 | ;; |
88 | m*[0-9]* ) | 127 | s*[0-9]* ) |
89 | i=${REPLY#?} | 128 | i=${REPLY#?} |
90 | i=$((i - 1)) | 129 | i=$((i - 1)) |
91 | if [ $i -gt 0 -a $i -lt ${#OPTIONS[@]} ] | 130 | if [ $i -gt 0 -a $i -lt ${#OPTIONS[@]} ] |
92 | then | 131 | then |
93 | w3m "${href[$i]}" | 132 | showpage "${href[$i]}" |
94 | fi | 133 | fi |
95 | ;; | 134 | ;; |
96 | esac | 135 | esac |
97 | done | 136 | done |
98 | } | 137 | } |
99 | 138 | ||
100 | search "${@:-music}" | 139 | isearch() |
140 | { | ||
141 | while read -e -p 'Search f-droid.org> ' | ||
142 | do | ||
143 | if [ "$REPLY" ] | ||
144 | then | ||
145 | search $REPLY | ||
146 | fi | ||
147 | done | ||
148 | } | ||
149 | |||
150 | if [ $# -gt 0 ] | ||
151 | then | ||
152 | search "$@" | ||
153 | else | ||
154 | isearch | ||
155 | fi | ||