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

Ivy Foster joyfulgirl at archlinux.us
Wed Jun 27 20:37:11 UTC 2012


The following commit has been merged in the master branch:
commit 23c56800314e5f2ca1cef9da4554981af19b7650
Author: Ivy Foster <joyfulgirl at archlinux.us>
Date:   Wed Jun 27 16:28:44 2012 -0400

    Updated searchable bookmarks.
    
        - Added documentation.
        - Fixed argument parsing.

diff --git a/AUTHORS b/AUTHORS
index 4de85f3..39871dd 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -123,6 +123,9 @@ Jason Ryan <jasonwryan at surfraw.org>
 Sara Fauzia <sara at archlinux.us>
         archpkg fix.
 
+Thomas Zervogiannis <tzervo at gmail.com>
+        Searchable bookmarks.
+
 Paulo Almeida <paulo at diasalmeida.com>
         elvi: priberam
 
diff --git a/ChangeLog b/ChangeLog
index ec981e1..b0b955b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,19 @@
-2012-06-01  Jason Ryan <jasonwryan at surfraw.org>
+2012-07-27  Ivy Foster  <joyfulgirl at archlinux.us>
+
+	* Fixed arg parsing in searchable bookmarks
+	* New variable: SURFRAW_bookmark_search_elvis
+	  + When using searchable bookmarks, if all else fails
+	    run this elvis. Defaults to google
+	* Updated manual to reflect changes to bookmarks
+
+2012-07-27  Thomas Zervogiannis <tzervo at gmail.com>
+
+	* Added searchable bookmarks
+
+	  + Bookmarks can now be searchable by adding '%s' to
+	    the url string.
+
+2012-06-01  Jason Ryan	<jasonwryan at surfraw.org>
 
 	* New elvi: github (search github.com)
 
diff --git a/surfraw.1.IN b/surfraw.1.IN
index fcca0dd..e47e2de 100644
--- a/surfraw.1.IN
+++ b/surfraw.1.IN
@@ -27,7 +27,7 @@ surfraw \- a fast unix command line interface to WWW services
 .B sr \-elvi
 .br
 .B sr
-.I bookmark
+.I [options] bookmark [search words]
 .br
 
 .SH DESCRIPTION
@@ -79,6 +79,12 @@ eg:
 
  ntk   http://www.ntk.net/
 
+If the url contains the string \fB%s\fP, you can specify an
+optional argument to the bookmark. Without an argument, only
+the domain will be returned. With arguments, \fb%s\fP will
+be replaced by the arguments. This obviates the need to
+create elvi for sites with very simple search options.
+
 To invoke a bookmark, use "surfraw bookmark" or "sr bookmark",
 and if an elvis of that name doesn't exist, it searches for a
 bookmark of that name instead.
diff --git a/surfraw.IN b/surfraw.IN
index 17227fa..69cebf8 100755
--- a/surfraw.IN
+++ b/surfraw.IN
@@ -268,6 +268,10 @@ w3_global_usage () {
 #-------------------------------------79 cols----------------------------------
     cat <<EOF
 Global options:
+  -bookmark-search-elvis=ELVIS	If args are passed to a non-searchable
+				bookmark, search with this elvis instead.
+				Default: $SURFRAW_bookmark_search_elvis
+				Environment: SURFRAW_bookmark_search_elvis
   -browser=EXECUTABLE		Set browser
 				Default: $SURFRAW_browser
   -elvi				List Surfraw mechanisms for conquering evil
@@ -330,6 +334,8 @@ w3_parse_option () {
     esac
     w3_parse_option_hook "$opt" "$optarg" && return 0
     case "$opt" in
+    -bookmark-search-elvis=*)
+        setopt SURFRAW_bookmark_search_elvis   $optarg ;;
 	-browser=*)	    setopt   SURFRAW_browser		$optarg	;;
 	-elvi)		    echo " GLOBAL ELVI:"
 			    list_elvi "$elvidir"
@@ -483,7 +489,7 @@ quote () {
 surfraw_usage() {
 	cat <<EOF
 Usage: $w3_argv0 [-help] [-elvi] elvis [elvioptions] [search terms]
-       $w3_argv0 [options] bookmark
+       $w3_argv0 [options] bookmark [search terms]
     If you wish to run the elvi directly, run "surfraw-update-path" to append
 	$elvidir to your \$PATH in your shell's config files.
     See surfraw-update-path(1) for details
@@ -495,27 +501,25 @@ EOF
 	w3_global_usage
 }
 
-# Browse URL or perform a search on URL(s) if search
-# terms are provided (use google elvi if URL has no %s
-# field or multiple URLS)
-browse_or_google ()
+# Browse URL or perform a search on URL(s) if search terms
+# are provided (use the user's elvis of choice if URL has no
+# %s field or multiple if multiple URLs are provided)
+parse_bookmark()
 {
     if [ -z "$w3_args" ]; then
         case "$bookmark" in
             *"%s"*) 
                 # Keep only the domain address, the rest could be garbage.
                 # This bookmark was probably meant to be used like that anyway.
-                get_domain_from_bookmark
+                $bookmark=$(get_domain_from_bookmark)
                 ;;
         esac
-        w3_browse_url "$bookmark"
     else
         escaped_args=$(w3_url_of_arg $w3_args)
 
         case "$bookmark" in
             *"%s"*) 
                 bookmark="$(printf '%s\n' "$bookmark" | sed "s|\%s|$escaped_args|")"
-                w3_browse_url "$bookmark"
                 ;;
             *)
                 n=${#bookmark[*]}
@@ -526,18 +530,21 @@ browse_or_google ()
                     i=$(($i+1))
                 done
 
-                googleargs="$w3_args $bookmark"
+                searchargs="$w3_args $bookmark"
 
                 i=1
                 while test $i -lt $n; do
-                    googleargs="$googleargs OR ${bookmark[$i]}"
+                    searchargs="$searchargs OR ${bookmark[$i]}"
                     i=$(($i+1))
                 done
 
-                google "$googleargs"
+                [ -z $SURFRAW_bookmark_search_elvis ] && \
+                    SURFRAW_bookmark_search_elvis=google
+                bookmark=$($SURFRAW_bookmark_search_elvis -print $searchargs)
                 ;;
         esac
     fi
+    echo $bookmark
 }
 
 get_domain_from_bookmark ()
@@ -621,7 +628,8 @@ then
 			if [ -n "$bookmark" ]
 			then
                 w3_parse_args $unquoted_opts $unquoted_searchterms
-                browse_or_google
+                bookmark=$(parse_bookmark)
+                w3_browse_url "$bookmark"
                 exit 0
 			else
 				echo "`basename $0`: $elvi: No elvis or bookmark with that name"

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



More information about the Surfraw-commits mailing list