aboutsummaryrefslogtreecommitdiff
path: root/sbo
diff options
context:
space:
mode:
Diffstat (limited to 'sbo')
-rwxr-xr-xsbo88
1 files changed, 88 insertions, 0 deletions
diff --git a/sbo b/sbo
new file mode 100755
index 0000000..fdc895e
--- /dev/null
+++ b/sbo
@@ -0,0 +1,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"