[Surfraw-commits] [SCM] surfraw - a fast unix command line interface to WWW branch, master, updated. surfraw_2-2-5_1-150-g50d1344

Ian Beckwith ianb at erislabs.net
Wed Jan 12 15:16:40 UTC 2011


The following commit has been merged in the master branch:
commit 066cffddf1e5f09d2650e4a9fd0fc4d39b4b69aa
Author: Ian Beckwith <ianb at erislabs.net>
Date:   Wed Jan 12 14:02:37 2011 +0000

    replaced duckduckgo elvi with kyle's more functional version

diff --git a/elvi/ddg b/elvi/ddg
deleted file mode 100755
index bdad209..0000000
--- a/elvi/ddg
+++ /dev/null
@@ -1,82 +0,0 @@
-#!/bin/sh
-# elvis: ddg            -- Securely search the web using duckduckgo (www.duckduckgo.com)
-# coder at kyleisom.net 20110105
-# relevant: https://duckduckgo.com/params.html
-# similar to duckduckgo elvi, adds more options and defaults to SSL.
-. surfraw || exit 1
-
-w3_config_hook () {
-    def     SURFRAW_ddg_results             "$SURFRAW_results"
-    def     SURFRAW_ddg_base_url            "www.duckduckgo.com"
-    def     SURFRAW_ddg_search              search
-    def     SURFRAW_ddg_params              "&kg=g"
-    defyn   SURFRAW_ddg_https_arg           0
-    defyn   SURFRAW_ddg_safe_arg            0
-    defyn   SURFRAW_ddg_redirect_arg        0
-    defyn   SURFRAW_ddg_use_javascript      0
-    defyn   SURFRAW_ddg_got_a_ducky_feeling 0
-}
-
-w3_usage_hook () {
-    cat <<EOF
-Usage: $w3_argv0 [options] [search words]...
-Description:
-  Surfraw search the web using DuckDuckGo (www.duckduckgo.com)
-Local options:
-    -d,-ducky,-l,-lucky         use in case of overwhelming feeling of duckiness
-    -j,-javascript              use javascript
-    -p,-safe                    enable safe search
-    -r,-redirect                use redirection
-    -s,-insecure                disable SSL search
-EOF
-    w3_global_usage
-}
-
-w3_parse_option_hook () {
-    opt="$1"
-    optarg="$2"
-    case "$opt" in
-    -d*|-l*)            setoptyn    SURFRAW_ddg_got_a_ducky_feeling 1 ;;
-    -j|-javascript*)    setoptyn    SURFRAW_ddg_use_javascript      1 ;;
-    -p|-safe*)		setoptyn    SURFRAW_ddg_safe_arg            1 ;;
-    -r|-redirect*)      setoptyn    SURFRAW_ddg_redirect_arg        1 ;;
-    -s|-sec*)           setoptyn    SURFRAW_ddg_https_arg           1 ;;
-    *) return 1 ;;
-    esac
-    return 0
-}
-
-w3_config
-w3_parse_args "$@"
-# w3_args now contains a list of arguments
-    
-if [ "${SURFRAW_ddg_https_arg}" = 0 ] ; then
-    SURFRAW_ddg_base_url="https://${SURFRAW_ddg_base_url}"
-else
-    SURFRAW_ddg_base_url="http://${SURFRAW_ddg_base_url}"
-fi
-
-# need to send the user to the non-javascript version if using a non-graphical
-# browser
-if [ "$SURFRAW_ddg_use_javascript" = 0 ]; then
-    SURFRAW_ddg_base_url="${SURFRAW_ddg_base_url}/lite"
-fi
-
-if [ "$SURFRAW_ddg_safe_arg" = 1 ]; then
-    SURFRAW_ddg_params="${SURFRAW_ddg_params}&kp=1"
-fi
-
-if [ "$SURFRAW_ddg_redirect_arg" = 1 ] ; then
-    SURFRAW_ddg_params="${SURFRAW_ddg_params}&kd=1"
-fi
-
-if [ "$SURFRAW_graphical" != "yes" ] ; then
-    SURFRAW_ddg_params="${SURFRAW_ddg_params}&kf=-1&kz=-1&kq=-1&kv=-1"
-fi
-
-escaped_args=`w3_url_of_arg $w3_args`
-if [ "$SURFRAW_ddg_got_a_ducky_feeling" = 1 ]; then
-    escaped_args="! ${escaped args}"
-fi
-
-w3_browse_url "${SURFRAW_ddg_base_url}/?q=${escaped_args}${SURFRAW_ddg_params}"
diff --git a/elvi/duckduckgo b/elvi/duckduckgo
index 7eb8d59..bdad209 100755
--- a/elvi/duckduckgo
+++ b/elvi/duckduckgo
@@ -1,26 +1,33 @@
 #!/bin/sh
-# elvis: duckduckgo	-- Search the web using Duckduckgo (www.duckduckgo.com)
-# ianb at erislabs.net 20100416
+# elvis: ddg            -- Securely search the web using duckduckgo (www.duckduckgo.com)
+# coder at kyleisom.net 20110105
+# relevant: https://duckduckgo.com/params.html
+# similar to duckduckgo elvi, adds more options and defaults to SSL.
 . surfraw || exit 1
 
 w3_config_hook () {
-    def   SURFRAW_duckduckgo_search ""
-    defyn SURFRAW_duckduckgo_lucky 0
+    def     SURFRAW_ddg_results             "$SURFRAW_results"
+    def     SURFRAW_ddg_base_url            "www.duckduckgo.com"
+    def     SURFRAW_ddg_search              search
+    def     SURFRAW_ddg_params              "&kg=g"
+    defyn   SURFRAW_ddg_https_arg           0
+    defyn   SURFRAW_ddg_safe_arg            0
+    defyn   SURFRAW_ddg_redirect_arg        0
+    defyn   SURFRAW_ddg_use_javascript      0
+    defyn   SURFRAW_ddg_got_a_ducky_feeling 0
 }
 
 w3_usage_hook () {
     cat <<EOF
 Usage: $w3_argv0 [options] [search words]...
 Description:
-  Surfraw search the web using Duckduckgo (duckduckgo.com)
-  Requires Javascript
+  Surfraw search the web using DuckDuckGo (www.duckduckgo.com)
 Local options:
-  -l, -lucky, -d, -ducky        Feeling d^Hlucky? Jump to first result.
-  -search=                      Search type
-          info          |       Information
-          shopping      |       Shopping
-                                Environment: SURFRAW_duckduckgo_search
-				Default is neither, use normal search.
+    -d,-ducky,-l,-lucky         use in case of overwhelming feeling of duckiness
+    -j,-javascript              use javascript
+    -p,-safe                    enable safe search
+    -r,-redirect                use redirection
+    -s,-insecure                disable SSL search
 EOF
     w3_global_usage
 }
@@ -29,8 +36,11 @@ w3_parse_option_hook () {
     opt="$1"
     optarg="$2"
     case "$opt" in
-    -search=*)       setopt   SURFRAW_duckduckgo_search  "$optarg" ;;
-    -d|-du*|-l|-lu*) setoptyn SURFRAW_duckduckgo_lucky   1         ;;
+    -d*|-l*)            setoptyn    SURFRAW_ddg_got_a_ducky_feeling 1 ;;
+    -j|-javascript*)    setoptyn    SURFRAW_ddg_use_javascript      1 ;;
+    -p|-safe*)		setoptyn    SURFRAW_ddg_safe_arg            1 ;;
+    -r|-redirect*)      setoptyn    SURFRAW_ddg_redirect_arg        1 ;;
+    -s|-sec*)           setoptyn    SURFRAW_ddg_https_arg           1 ;;
     *) return 1 ;;
     esac
     return 0
@@ -39,22 +49,34 @@ w3_parse_option_hook () {
 w3_config
 w3_parse_args "$@"
 # w3_args now contains a list of arguments
-
-if test -z "$w3_args"; then
-    w3_browse_url "http://duckduckgo.com/"
+    
+if [ "${SURFRAW_ddg_https_arg}" = 0 ] ; then
+    SURFRAW_ddg_base_url="https://${SURFRAW_ddg_base_url}"
 else
-    escaped_args=`w3_url_of_arg $w3_args`
-    url="http://duckduckgo.com/?q=${escaped_args}"
-    # -lucky & -search= are mutually exclusive - prefer -lucky
-    if ifyes SURFRAW_duckduckgo_lucky; then
-	url="${url}&v=i"
-    elif test -n "$SURFRAW_duckduckgo_search"; then
-	case "$SURFRAW_duckduckgo_search" in
-	    i*) url="${url}&v=d" ;;
-	    s*) url="${url}&v=s" ;;
-	    *)  err "duckduckgo: unknown search type \"${SURFRAW_duckduckgo_search}\"" ;;
-	esac
-    fi
-
-    w3_browse_url "$url"
+    SURFRAW_ddg_base_url="http://${SURFRAW_ddg_base_url}"
+fi
+
+# need to send the user to the non-javascript version if using a non-graphical
+# browser
+if [ "$SURFRAW_ddg_use_javascript" = 0 ]; then
+    SURFRAW_ddg_base_url="${SURFRAW_ddg_base_url}/lite"
+fi
+
+if [ "$SURFRAW_ddg_safe_arg" = 1 ]; then
+    SURFRAW_ddg_params="${SURFRAW_ddg_params}&kp=1"
+fi
+
+if [ "$SURFRAW_ddg_redirect_arg" = 1 ] ; then
+    SURFRAW_ddg_params="${SURFRAW_ddg_params}&kd=1"
+fi
+
+if [ "$SURFRAW_graphical" != "yes" ] ; then
+    SURFRAW_ddg_params="${SURFRAW_ddg_params}&kf=-1&kz=-1&kq=-1&kv=-1"
 fi
+
+escaped_args=`w3_url_of_arg $w3_args`
+if [ "$SURFRAW_ddg_got_a_ducky_feeling" = 1 ]; then
+    escaped_args="! ${escaped args}"
+fi
+
+w3_browse_url "${SURFRAW_ddg_base_url}/?q=${escaped_args}${SURFRAW_ddg_params}"

-- 
surfraw -  a fast unix command line interface to WWW



More information about the Surfraw-commits mailing list