[dev] [surf] shell script to do bookmarks, history, and other things

From: Peter John Hartman <peterjohnhartman_AT_gmail.com>
Date: Wed, 31 Mar 2010 13:14:26 -0400 (EDT)

Hi Folks,

So, I've cobbled together the attached shell script to do most of what I
want to do with surf, including history, smart prefixes, and bookmarks.
The upshot is that one doesn't need the history patch and the searchengines

I'd appreciate comments on this, esp.\ with respect to how I can figure
out what the TITLE value is of a new uri. The current technique does
a nasty little loop; and it still sometimes returns odd values for the
TITLE. You can see that in the comments to the code.

In config.h replace the SETPROP line with:

#define SETPROP(p) { .v = (char *[]){ "/bin/sh", "-c", "surf.sh $1 $0", p, winid, NULL } }

And you also bind:


============= surf.sh ===================================================

# TODO add to surf-start.sh a cleanup routine to get rid of all old entries
# $1 = $xid
# $2 = $p = _SURF_FIND _SURF_BMARK _SURF_URI i.e. what SETPROP states in config.h

function s_add() {
         timestamp=`date +%Y%m%d%H%M%S`
         grep "$url" ~/.surf/history >/dev/null || echo -e "$url\t$name\t$timestamp" >> ~/.surf/history

function s_get_uri() {
         xprop -id $xid _SURF_URI | cut -d '"' -f 2

function s_get_name() {
         xprop -id $xid WM_ICON_NAME | cut -d '"' -f 2

function s_set_uri() {
         xprop -id $xid -f _SURF_URI 8s -set _SURF_URI "$newuri" 2>/dev/null >/dev/null


if [[ $p == "_SURF_FIND" ]]; then
         dmenu -b -p ":"
elif [[ $p == "_SURF_BMARK" ]]; then
         cur=`s_get_uri $xid`
         name=`s_get_name $xid`
             s_add "$cur" "$name"
         # display the history PLUS the current uri via dmenu
         cur=`s_get_uri $xid`
         curname=`s_get_name $xid`
             cp ~/.surf/history /tmp/surf.history.$$
             echo -e "$cur\t$curname\t$timestamp" >> /tmp/surf.history.$$
             selection=`tac /tmp/surf.history.$$ | awk 'BEGIN { FS="\t" } {print $1" "$2}' | dmenu -b -l 10`
         rm -f /tmp/surf.history.$$

         # if we hit escape, then exit
         if [[ $selection == "" ]]; then

         # post "smart" process
         # entries ($selection) will either be:
         # gg foobar foo foo2 foo3 i.e. <SMART ABBV><SPACE><VALUE>
         # or:
         # http://www.google.com/ NAME OF SITE i.e. <URL><SPACE><NAME>

         # this removes trailing whitespace, ie when there is no name
         OPTION=$(echo $selection | sed -e 's/^ *//g;s/ *//g' | awk '{print $1}')

         if [[ $OPTION == "gg" ]]; then
             VALUE=$(echo $selection | sed 's/gg //' | urlencode.sh)
             s_set_uri $xid $URL
             s_add "$selection" ""
         elif [[ $OPTION == "ut" ]]; then
             VALUE=$(echo $selection | sed 's/ut //' | urlencode.sh)
             s_set_uri $xid $URL
             s_add "$selection" ""
             # otherwise go to the url they enter
             URL=$(echo $selection | awk '{print $1}')
             s_set_uri $xid $URL
             # NASTY little hack to figure out what the REAL TITLE is.
             name="`s_get_name $xid`"
             while echo $name | grep "[*%\]"; do
                     name=`s_get_name $xid`
             s_add $URL "$name"

Peter Hartman

sic dicit magister P.
Received on Wed Mar 31 2010 - 17:14:26 UTC

This archive was generated by hypermail 2.2.0 : Wed Mar 31 2010 - 17:24:02 UTC