index.md - sites - public wiki contents of suckless.org | |
git clone git://git.suckless.org/sites | |
Log | |
Files | |
Refs | |
--- | |
index.md (5430B) | |
--- | |
1 Bookmarks for surf | |
2 ================== | |
3 | |
4 Description | |
5 ----------- | |
6 | |
7 This script enables bookmarks, url handlers, and history (find and url e… | |
8 NB: This script obviates the need to patch surf at all with, e.g., the h… | |
9 | |
10 Keybindings | |
11 ----------- | |
12 ^I (get some information) | |
13 ^b (bookmark current url with given tags) | |
14 ^g (open url with bookmark autocompletion) | |
15 ^G (open url without bookmark autocompletion) | |
16 | |
17 URL handlers | |
18 ------------ | |
19 This script implements several url handlers | |
20 "d " (bookmark current url in delicious) | |
21 "t " (create tinyurl from current page) | |
22 "w word .." (lookup word in wikipedia) | |
23 "g word .." (google for given word) | |
24 "y word .." (search in youtube) | |
25 "x word .." (remove an entry from the bookmarks file) | |
26 | |
27 Author | |
28 ------ | |
29 | |
30 * The code was originally from Peter John Hartman, then filtered through… | |
31 and now back to Peter John Hartman. You can get the latest version at… | |
32 | |
33 Installation | |
34 ------------ | |
35 | |
36 Copy the following code into a shellscript named 'surf.sh' in $PATH. Edi… | |
37 | |
38 Code | |
39 ---- | |
40 #!/bin/sh | |
41 # v. 2.0 - upgrade based on surf 4.0 | |
42 # Creative Commons License. Peter John Hartman (http://individu… | |
43 # Much thanks to nibble and pancake who have a different surf.sh… | |
44 # doesn't do the history bit. | |
45 # | |
46 # this script does: | |
47 # * stores history of: (1) successful uri entries; (2) certain s… | |
48 # * direct bookmark (via ^b) | |
49 # * information debug (via ^I) | |
50 # * smart prefixes e.g. g for google search, t for tinyurl, etc. | |
51 # * delete (with smart prefix x) | |
52 # | |
53 # $1 = $xid | |
54 # $2 = $p = _SURF_FIND _SURF_BMARK _SURF_URI (what SETPROP sets … | |
55 # | |
56 # // replace default setprop with this one | |
57 # #define SETPROP(p) { .v = (char *[]){ "/bin/sh", "-c", "surf.s… | |
58 # | |
59 # { MODKEY, GDK_b, spawn, SETPROP("_SURF_BMARK") }, | |
60 # { MODKEY|GDK_SHIFT_MASK, GDK_i, spawn, SETPROP("_SURF_INFO") }, | |
61 # { MODKEY|GDK_SHIFT_MASK, GDK_g, spawn, SETPROP("_SURF_URI_RAW"… | |
62 | |
63 font='-*-terminus-medium-*-*-*-*-*-*-*-*-*-*-*' | |
64 normbgcolor='#181818' | |
65 normfgcolor='#e9e9e9' | |
66 selbgcolor=$normbgcolor | |
67 selfgcolor='#dd6003' | |
68 bmarks=~/.surf/history.txt | |
69 ffile=~/.surf/find.txt | |
70 | |
71 pid=$1 | |
72 fid=$2 | |
73 xid=$3 | |
74 | |
75 dmenu="dmenu -nb $normbgcolor -nf $normfgcolor \ | |
76 -sb $selbgcolor -sf $selfgcolor" | |
77 | |
78 s_get_prop() { # xprop | |
79 xprop -id $xid $1 | cut -d '"' -f 2 | |
80 } | |
81 | |
82 s_set_prop() { # xprop value | |
83 [ -n "$2" ] && xprop -id $xid -f $1 8s -set $1 "$2" | |
84 } | |
85 | |
86 s_write_f() { # file value | |
87 [ -n "$2" ] && (sed -i "\|$2|d" $1; echo "$2" >> $1) | |
88 #grep "$uri" $bmarks >/dev/null 2>&1 || echo "$uri" >> $… | |
89 } | |
90 | |
91 s_set_write_proper_uri() { # uri | |
92 # TODO: (xprop -spy _SURF_URI ... | while read name __ v… | |
93 # input is whatever the use inputed, so don't store that! | |
94 # first, clear the name field because surf doesn't somet… | |
95 #s_set_prop WM_ICON_NAME "" | |
96 # set the uri | |
97 s_set_prop _SURF_GO "$1" | |
98 # get the new name | |
99 name=`s_get_prop WM_ICON_NAME` | |
100 # loop until the [10%] stuff is finished and we have a l… | |
101 #while echo $name | grep "[*%\]" >/dev/null 2>&1; do | |
102 # name=`s_get_prop WM_ICON_NAME` | |
103 #done | |
104 # bail on error and don't store | |
105 #if [[ $name != "Error" ]]; then | |
106 # uri=`s_get_prop _SURF_URI` | |
107 # store to the bmarks file the OFFICIAL url (wit… | |
108 s_write_f $bmarks "$1" | |
109 #grep "$uri" $bmarks >/dev/null 2>&1 || echo "$u… | |
110 #fi | |
111 } | |
112 | |
113 case "$pid" in | |
114 "_SURF_INFO") | |
115 xprop -id $xid | sed 's/\t/ /g' | $dmenu -fn "$font" … | |
116 ;; | |
117 "_SURF_FIND") | |
118 find="`tac $ffile 2>/dev/null | $dmenu -fn "$font" -b -p… | |
119 s_set_prop _SURF_FIND "$find" | |
120 s_write_f $ffile "$find" | |
121 ;; | |
122 "_SURF_BMARK") | |
123 uri=`s_get_prop _SURF_URI` | |
124 s_write_f $bmarks "$uri" | |
125 ;; | |
126 "_SURF_URI_RAW") | |
127 uri=`echo $(s_get_prop _SURF_URI) | $dmenu -fn "$font" -… | |
128 s_set_prop _SURF_GO "$uri" | |
129 ;; | |
130 "_SURF_URI") | |
131 sel=`tac $bmarks 2> /dev/null | $dmenu -fn "$font" -b -l… | |
132 [ -z "$sel" ] && exit | |
133 opt=$(echo $sel | cut -d ' ' -f 1) | |
134 arg=$(echo $sel | cut -d ' ' -f 2-) | |
135 save=0 | |
136 case "$opt" in | |
137 "d") # del.icio.us | |
138 uri="http://del.icio.us/save?url=`s_get_prop _SU… | |
139 ;; | |
140 "g") # google for it | |
141 uri="http://www.google.com/search?q=$arg" | |
142 save=1 | |
143 ;; | |
144 "t") # tinyurl | |
145 uri="http://tinyurl.com/create.php?url=`s_get_pr… | |
146 ;; | |
147 "w") # wikipedia | |
148 uri="http://wikipedia.org/wiki/$arg" | |
149 save=1 | |
150 ;; | |
151 "u") # utoronto | |
152 uri="http://search2.library.utoronto.ca/UTL/inde… | |
153 save=1 | |
154 ;; | |
155 "y") # youtube | |
156 uri="http://www.youtube.com/results?search_query… | |
157 save=1 | |
158 ;; | |
159 "x") # delete | |
160 sed -i "\|$arg|d" $bmarks | |
161 exit; | |
162 ;; | |
163 *) | |
164 uri="$sel" | |
165 save=2 | |
166 ;; | |
167 esac | |
168 | |
169 # only set the uri; don't write to file | |
170 [ $save -eq 0 ] && s_set_prop _SURF_GO "$uri" | |
171 # set the url and write exactly what the user inputed to… | |
172 [ $save -eq 1 ] && (s_set_prop _SURF_GO "$uri"; s_write_… | |
173 # try to set the uri only if it is a success | |
174 [ $save -eq 2 ] && s_set_write_proper_uri "$uri" | |
175 ;; | |
176 *) | |
177 echo Unknown xprop | |
178 ;; | |
179 esac |