blob: fdc895e1a66d7e43d60c4e4d4567dea6d120d8f3 (
plain)
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
#!/bin/sh
# elvis: sbo -- Search SlackBuilds.org packages
# Author: B. Watson (yalhcru at gmail)
# Licensed under the WTFPL. See http://www.wtfpl.net/txt/copying/ for details.
. surfraw || exit 1
if [ "$( type -p wget )" = "" ]; then
err "wget is required for this. please install it."
fi
get_slack_ver() {
local ver sitevers topver i
# initially set to the currently running version, if we can
if [ -e /etc/slackware-version ]; then
ver="$( cut -d' ' -f2 < /etc/slackware-version )"
fi
# now check the site, make sure it's a supported version (e.g. not -current)
sitevers="$(
wget -qO- "https://slackbuilds.org" | \
grep -A1 '<select *name="sv"' | \
tail -1 | \
sed \
-e 's,^[[:space:]]*,,' \
-e 's,<option value="[^"]*"[^>]*>\([0-9][^"]*\)</option>,\1 ,g' \
-e 's,[[:space:]]*</select>.*,,'
)"
# if we can't get the local version *or* the list of versions
# from the site, just take a wild guess.
if [ -z "$sitevers" ]; then
echo "${ver:-14.2}"
return
fi
for i in $sitevers; do
topver="$i"
if [ "$i" = "$ver" ]; then
echo "$ver"
return
fi
done
# fall back to the highest-numbered version on the site
echo "$topver"
return
}
w3_config_hook() {
def SURFRAW_slack_version "$( get_slack_ver )"
}
w3_usage_hook() {
cat <<EOF
Usage: $w3_argv0 [options] [search words]...
Description:
Surfraw search packages on SlackBuilds.org
Local options:
-ver=VERSION Slackware version (Currently $SURFRAW_slack_version)
EOF
w3_global_usage
}
w3_parse_option_hook() {
opt="$1"
optarg="$2"
case "$opt" in
-v*=*) setopt SURFRAW_slack_version "$optarg" ;;
*) return 1 ;;
esac
return 0
}
w3_config
w3_parse_args "$@"
# example URL:
# http://slackbuilds.org/result/?search=test&sv=14.2
escaped_args="$( w3_url_of_arg $w3_args )"
url="https://slackbuilds.org/result/?search=${escaped_args}&sv=${SURFRAW_slack_version}"
w3_browse_url "$url"
|