Centurion / .config / surfraw / elvi / archpkg

# elvis: archpkg		-- Search Arch Linux Packages (www.archlinux.org/packages/)
# Author: jason ryan • http://jasonwryan.com

. surfraw || exit 1

w3_config_hook () {
def   SURFRAW_arch_ix           "$SURFRAW_ix"
def   SURFRAW_arch_repo         "$SURFRAW_repo"
def   SURFRAW_arch_date         "$SURFRAW_date"
def   SURFRAW_arch_results       25	

w3_usage_hook () {
    cat <<EOF
Usage: $w3_argv0 [options] [search string]
Description: Surfraw search Arch Linux packages (www.archlinux.org)

	Local options:
		any        |   Any (default)
		i686       |   i686
		x86_64     |   x86_64

		comm       |   Community
		commtest   |   Community-Testing
		core       |   Core
		extra      |   Extra
		multi      |   Multilib
		multitest  |   Multilib-Testing
		test       |   Testing
		               Default: All

	-date=UPDATED  | -d=UPDATED (format: YYYY-MM-DD)

	-num=NUMBER    |  Number of results per page
	                  Default: $SURFRAW_arch_results


w3_parse_option_hook () {
    case "$opt" in
	-a*=*)	setopt   SURFRAW_arch_ix        $optarg ;;
	-r*=*)	setopt   SURFRAW_arch_repo      $optarg ;;
	-d*=*)	setopt   SURFRAW_arch_date      $optarg ;;
	-n*=*)	setopt   SURFRAW_arch_results   $optarg ;;
	    *)	return 1 ;;
    return 0

w3_parse_args "$@"

# selected repository
case "$SURFRAW_arch_repo" in
	comm)     repo="Community"         ;;
	commtest) repo="Community-Testing" ;;
	core)     repo="Core"              ;;
	extra)    repo="Extra"             ;;
	multi)    repo="Multilib"          ;;
	multitest)repo="Multilib-Testing"  ;;
	test)     repo="Testing"           ;;
	*)        repo=""                  ;;

# no arguments present
if [ -z "$w3_args" ]; then
    w3_browse_url "http://www.archlinux.org/packages/"

# if w3_args contains a list of arguments
escaped_args=$(w3_url_of_arg $w3_args)

	# repository and architecture
	if [ -n "$SURFRAW_arch_repo" -a "$SURFRAW_arch_ix" ]; then
	w3_browse_url "${base}&arch=${SURFRAW_arch_ix}&repo=${repo}&q=${escaped_args}&maintainer=&last_update=${SURFRAW_arch_date}&flagged=&limit=${SURFRAW_arch_results}"
	# check for repository
	elif [ -n "$SURFRAW_arch_repo" ]; then
	w3_browse_url "${base}&repo=${repo}&q=${escaped_args}&maintainer=&last_update=${SURFRAW_arch_date}&flagged=&limit=${SURFRAW_arch_results}"

	# just architecture
	elif [ -n "$SURFRAW_arch_ix" ]; then
	w3_browse_url "${base}&arch=${SURFRAW_arch_ix}&q=${escaped_args}&maintainer=&last_update=${SURFRAW_arch_date}&flagged=&limit=${SURFRAW_arch_results}"

	# none of the above...
	w3_browse_url "${base}&q=${escaped_args}&maintainer=&last_update=${SURFRAW_arch_date}&flagged=&limit=${SURFRAW_arch_results}"
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.