sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

index.md (2835B)


      1 Bookmarks for surf
      2 ==================
      3 
      4 Description
      5 -----------
      6 
      7 This script enables bookmarks and url handlers for surf.
      8 
      9 Keybindings
     10 -----------
     11 	^b (bookmark current url with given tags)
     12 	^g (open url with bookmark autocompletion)
     13 	^G (open url without bookmark autocompletion)
     14 
     15 URL handlers
     16 ------------
     17 	This script implements several url handlers
     18 	"d " (bookmark current url in delicious)
     19 	"t " (create tinyurl from current page)
     20 	"w word .." (lookup word in wikipedia)
     21 	"g word .." (google for given word)
     22 	"y word .." (search in youtube)
     23 
     24 Author
     25 ------
     26 
     27 * The code was originally from Peter John Hartman, but hardly simplified by pancake and nibble.
     28 
     29 Installation
     30 ------------
     31 
     32 Copy the following code into a shellscript named 'surf.sh' in $PATH. Edit config.h according to the rules explained in header.
     33 
     34 Code
     35 ----
     36 	#!/bin/sh
     37 	# $1 = $xid
     38 	# $2 = $p = _SURF_FIND _SURF_BMARK _SURF_URI _SURF_URI_RAW (what SETPROP sets in config.h)
     39 	#
     40 	# // replace default setprop with this one
     41 	# #define SETPROP(p) { .v = (char *[]){ "/bin/sh", "-c", "surf.sh $0 $1", winid, p, NULL } }
     42 	#
     43 	# // fix shift+slash keybinding in spanish keyboard (f.example)
     44 	# { MODKEY,               GDK_g,      spawn,      SETPROP("_SURF_URI") },
     45 	# { MODKEY|GDK_SHIFT_MASK,GDK_g,      spawn,      SETPROP("_SURF_URI_RAW") },
     46 	# { MODKEY,               GDK_f,      spawn,      SETPROP("_SURF_FIND") },
     47 	# { MODKEY,               GDK_b,      spawn,      SETPROP("_SURF_BMARK") },
     48 
     49 	font='-*-terminus-medium-*-*-*-*-*-*-*-*-*-*-*'
     50 	normbgcolor='#181818'
     51 	normfgcolor='#e9e9e9'
     52 	selbgcolor='#dd6003'
     53 	selfgcolor='#e9e9e9'
     54 	bmarks=~/.surf/bookmarks.txt
     55 
     56 	xid=$1
     57 	p=$2
     58 	uri=`xprop -id $xid _SURF_URI | cut -d '"' -f 2`
     59 	kw=`xprop -id $xid _SURF_FIND | cut -d '"' -f 2`
     60 	dmenu="dmenu -fn $font -nb $normbgcolor -nf $normfgcolor \
     61 		   -sb $selbgcolor -sf $selfgcolor"
     62 
     63 	s_xprop() {
     64 		[ -n "$2" ] && xprop -id $xid -f $1 8s -set $1 "$2"
     65 	}
     66 
     67 	case "$p" in
     68 	"_SURF_FIND")
     69 		ret="`echo $kw | $dmenu -p find:`"
     70 		s_xprop _SURF_FIND "$ret"
     71 		;;
     72 	"_SURF_BMARK")
     73 		grep "$uri" $bmarks >/dev/null 2>&1 || echo "$uri" >> $bmarks
     74 		;;
     75 	"_SURF_URI_RAW")
     76 		ret=`echo $uri | $dmenu -p "uri:"`
     77 		s_xprop _SURF_GO "$ret"
     78 		;;
     79 	"_SURF_URI")
     80 		sel=`tac $bmarks 2> /dev/null | $dmenu -p "uri [dgtwy*]:"`
     81 		[ -z "$sel" ] && exit
     82 		opt=$(echo $sel | cut -d ' ' -f 1)
     83 		arg=$(echo $sel | cut -d ' ' -f 2-)
     84 		case "$opt" in
     85 		"d") # del.icio.us
     86 			ret="http://del.icio.us/save?url=$uri"
     87 			;;
     88 		"g") # google for it
     89 			ret="http://www.google.com/search?q=$arg"
     90 			;;
     91 		"t") # tinyurl
     92 			ret="http://tinyurl.com/create.php?url=$uri"
     93 			;;
     94 		"w") # wikipedia
     95 			ret="http://wikipedia.org/wiki/$arg"
     96 			;;
     97 		"y") # youtube
     98 			ret="http://www.youtube.com/results?search_query=$arg&aq=f"
     99 			;;
    100 		*)
    101 			ret="$sel"
    102 			;;
    103 		esac
    104 		s_xprop _SURF_GO "$ret"
    105 		;;
    106 	*)
    107 		echo Unknown xprop
    108 		;;
    109 	esac