[dev] [surf] Call a script from within surf and an alternative to tabs

From: hailukah <shaw.josh_AT_gmail.com>
Date: Wed, 23 Sep 2009 12:42:42 -0500

Hi all,

First a little reasoning for this. After years of using a tabbed
browser I've become accustomed to going through a search engine listing
or a forum and middle clicking everything that looked interesting and
then going through the tabs one by one. After trying out surf and
getting spoilt by the clean interface and quick speeds I've begun
using it full time. So thank you to everyone who has helped develop
this less sucking browser.

However, I do need a way of keeping up with certain pages. I like
having a list of "bookmarks" so I can quickly navigate to a frequently
viewed site. I also need a way of remembering an arbitrary list of
urls for the sort term.

I understand the lack of tabs in surf, and I agree that it is better
not to have them in the first place. In fact, if I'd seen a better
solution in the past I would have switched.

After some tinkering I've come up with a method that works for me. It
involves a single file and three commands to manipulate it. I have a
file at ~/.surf/stack. I can add urls (stack), and pull from them
either FILO (unstack), or FIFO (go). I use the FIFO method like
bookmarks and the FILO method in place of tabs. The FILO method also
removes the visited url from the stack. This solves, for me, the
problems of not having bookmarks or short term url storage.

I can produce a patch of this if desired, but rather than post a patch
and have to update it with each new version of surf I'll just add
instructions for the changes here. (I will probably also add it to the
wiki, I just need to figure out the Hg system :) ).

The changes to surf can all be contained in config.h:

1.) Add the following line above #define MODKEY GDK_CONTROL_MASK

static void spawn(Client *c, const Arg *arg);

2.) Add this function to the bottom of config.h

void
spawn(Client *c, const Arg *arg) {
        const gchar *command = (gchar *)arg->v;
        const gchar *xid = g_strdup_printf("%u",
                (guint)GDK_WINDOW_XID(GTK_WIDGET(c->win)->window));
        gdk_display_sync(gtk_widget_get_display(c->win));
        if (fork() == 0)
                execlp("/PATH/TO/surf-script.sh", "surf-script.sh",
                        command, xid, webkit_web_view_get_uri(c->view),
                        NULL);
}

3.) Add the appropriate keys

{ MODKEY, GDK_s, spawn, { .v = "stack" },Any },
{ MODKEY, GDK_u, spawn, { .v = "unstack" }, Any },
{ MODKEY, GDK_g, spawn, { .v = "go" }, Any },

You'll have to reassign the showurl key to something other than MODKEY
g.

The spawn function calls surf-script.sh with three arguments. The
first is the argument to the the spawn function (e.g. stack), the next
is the xid of the surf instance calling the script, and the third
argument is the current url. This way a script can be written to
perform any desired function with either the xid (for changing the
_SURF_URL with xprop) or the url (for bookmarking).

Here's an example of what would be called:

/PATH/TO/surf-script.sh go 27263010 http://suckless.org/

My surf-script.sh is attached, but you'll probably want to make changes
or write your own. Mine uses dmenu for the url selection and dzen for
a notification.

I'd appreciate any comments, suggestions or effyou's (maybe I should
post as HTML :P ).

Regards,

Josh

Received on Wed Sep 23 2009 - 17:42:42 UTC

This archive was generated by hypermail 2.2.0 : Wed Sep 23 2009 - 17:48:01 UTC