Re: [dev] [surf] Search engine keyboard shortcut suggestion

From: Stanimir Dragiev <stanio_AT_cs.tu-berlin.de>
Date: Sun, 21 Mar 2010 10:30:20 +0100

* Kalle Arvidsson <klaa379_AT_gmail.com> [2010-03-20 21:23]:
> On Sat, Mar 20, 2010 at 02:45:40PM -0400, Paul O'Leary McCann wrote:
> > On Sat, Mar 20, 2010 at 01:53:17PM -0400, Brandon Ros wrote:
> > > The configuration file would contain the URL to append the URL-encoded
> > > terms to and a keyboard shortcut.
> >
> > There's a patch for that:
> >
> > http://surf.suckless.org/patches/searchengines
> >
> > I'd appreciate its incorporation in the mainline, though, as well as
> > sourcing a file rather than having them compiled in. -POLM
> >
>
> I don't think this needs to be a part of the browser, why not use an
> external program?

+1

It's better done outside surf. With the benefit of multiple sane (scriptable)
browser (or other apps) sharing history, bookmarks, keywords, whatever. As an
example:

~/bin/bmark-keywords is a shell script that does:

- return $1 if it's an URL
- find the URL corresponding to keyword $1 according to simple bookmark file
  - substitute the rest of $@ for '%s' in the found URL
  - return the URL

I use it in wrappers for w3m, lynx, surf, like

        % www_dump leo cow

making use of the following item in the bookmarks file:
http://dict.leo.org/ende?lang=de&spellToler=on&relink=on&search=%s :leo

Or inside scriptable browsers, e.g. surf, uzbl, or with the dictionary binding
of w3m, for instance:

---->8--------- surf/config.h
[...]
#define SETURI() { .v = (char *[]){ "/bin/sh", "-c", \
        "query=\"`xprop -id $0 _SURF_URI | cut -d '\"' -f 2 | dmenu `\" && " \
        "prop=\"`~/bin/bmark-keywords $query`\" && " \
        "xprop -id $0 -f _SURF_URI 8s -set _SURF_URI \"$prop\" " \
        winid, NULL } }
#define PASTEURI() { .v = (char *[]){ "/bin/sh", "-c", \
        "query=\"`sselp`\" && " \
        "prop=\"`~/bin/bmark-keywords $query`\" && " \
        "xprop -id $0 -f _SURF_URI 8s -set _SURF_URI \"$prop\" " \
        winid, NULL } }
[...]
----8<--------- surf/config.h

Or with poor man's command line history enabled, if you like:

---->8--------- surf/config.h
[...]
#define SETURI() { .v = (char *[]){ "/bin/sh", "-c", \
        "curr=\"`xprop -id $0 _SURF_URI | cut -d '\"' -f 2`\" && " \
        "query=\"`(echo $curr; cat ~/.surf/history-cl) | dmenu `\" && " \
        "prop=\"`~/bin/bmark-keywords $query`\" && " \
        "xprop -id $0 -f _SURF_URI 8s -set _SURF_URI \"$prop\"; " \
        "grep \"$query\" ~/.surf/history-cl || echo \"$query\" >> ~/.surf/history-cl ", \
        winid, NULL } }
#define PASTEURI() { .v = (char *[]){ "/bin/sh", "-c", \
        "query=\"`sselp`\" && " \
        "prop=\"`~/bin/bmark-keywords $query`\" && " \
        "xprop -id $0 -f _SURF_URI 8s -set _SURF_URI \"$prop\" ; " \
        "grep \"$query\" ~/.surf/history-cl || echo \"$query\" >> ~/.surf/history-cl ", \
        winid, NULL } }
[...]
----8<--------- surf/config.h

cheers

-- 
 stanio_
Received on Sun Mar 21 2010 - 09:30:20 UTC

This archive was generated by hypermail 2.2.0 : Sun Mar 21 2010 - 09:48:02 UTC