Surfraw

November 6, 2020

My first elvi searches Programming Praxis:

#!/bin/sh

. surfraw || exit 1

w3_usage_hook () {
    cat <<EOF
Usage: $w3_argv0 [search words]…
Description:
  Search Programming Praxis
EOF
    w3_global_usage
}

w3_config
w3_parse_args "$@"
if test -z "$w3_args"; then
    w3_browse_url "https://programmingpraxis.com/"
else
    escaped_args=w3_url_of_arg $w3_args
    w3_browse_url "http://programmingpraxis.com?s=${escaped_args}"
fi

And my second elvi interfaces to the very useful cheat program:

#!/bin/sh

. surfraw || exit 1

w3_usage_hook () {
    cat <<EOF
Usage: $w3_argv0 [search words]…
Description:
  Search Cheat Sheets
EOF
    w3_global_usage
}

w3_config
w3_parse_args "$@"
if test -z "$w3_args"; then
    curl cheat.sh
else
    escaped_args=w3_url_of_arg $w3_args
    curl cheat.sh/${escaped_args}
fi

Have fun! [ I hate the damned new smart editor on WordPress. ]

Advertisement

Pages: 1 2

2 Responses to “Surfraw”

  1. Zack said

    Interesting. For the record, there is an online tool that does the same, with a large variety of options and customizations. It’s called Searx. Have a nice weekend!

  2. chaw said

    Here is a very simple elvi for a simple search of the Bangor Daily News site.

    #!/bin/sh
    # $Id: msg.txt,v 1.1 2020/11/06 14:58:45 chaw Exp $
    # elvis: bangordailynews        -- Search Bangor Daily News (bangordailynews.com)
    . surfraw || exit 1
    
    w3_config_hook () {
        # Nothing yet.
    }
    
    w3_usage_hook () {
        cat <<EOF
    Usage: $w3_argv0 [options] [search words]...
    Description:
      Surfraw search Bangor Daily News (bangordailynews.com)
    (There are no local options.)
    EOF
        w3_global_usage
    }
    
    # no options currently
    w3_parse_option_hook () {
        opt="$1"
        optarg="$2"
        case "$opt" in
        # -r*=*)      setopt   SURFRAW_google_results "$optarg" ;;
        *) return 1 ;;
        esac
        return 0
    }
    
    w3_config
    w3_parse_args "$@"
    # w3_args now contains a list of arguments
    
    url="https://bangordailynews.com/"
    
    escaped_args=`w3_url_of_arg $w3_args`
    url="${url}?s=${escaped_args}"
    
    w3_browse_url "$url"
    

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: