index.md - sites - public wiki contents of suckless.org | |
git clone git://git.suckless.org/sites | |
Log | |
Files | |
Refs | |
--- | |
index.md (2443B) | |
--- | |
1 Quick searching with dmenu | |
2 ========================== | |
3 | |
4 Description | |
5 ----------- | |
6 | |
7 Prompts for a query with dmenu and posts it to the selected search engin… | |
8 The engine is specified by a single-character code that precedes the | |
9 actual query, e.g. 'w pancakes' would search en.wikipedia.org for the st… | |
10 'pancakes'. This reduces the necessary shell plumbing to a couple of pip… | |
11 and a case statement. | |
12 | |
13 Character ugliness in the query is avoided using od and tr. This | |
14 has worked so far. | |
15 | |
16 **EDIT:** Replaced xxd with od and eliminated a sed pipe. Replaced cut p… | |
17 with sh variable expansion. | |
18 | |
19 Author | |
20 ------ | |
21 | |
22 Wolfgang Corcoran-Mathe | |
23 | |
24 Installation | |
25 ------------ | |
26 | |
27 Copy the following code into an executable file and place it in PATH. Ed… | |
28 surf/config.def.h as described in the header. | |
29 | |
30 Code | |
31 ---- | |
32 | |
33 #!/bin/sh | |
34 # | |
35 # surf_qsearch: | |
36 # Search script for surf. Takes the surf window id as argument. | |
37 # POSIX compliant and GNU-free, I think. | |
38 # | |
39 # Add something like the following to your surf/config.(def.)h, … | |
40 # surf_qsearch with the name of the file you've copied this code… | |
41 # | |
42 # /* Quick searching. */ | |
43 # #define QSEARCH { \ | |
44 # .v = (char *[]){"/bin/sh", "-c", "surf_qsearch $0 $1", win… | |
45 # } | |
46 # | |
47 # Add a keybinding in keys[]: | |
48 # | |
49 # { MODKEY, GDK_q, spawn, QSEARCH }, | |
50 # | |
51 | |
52 # Get the full query. The 'echo | dmenu' idiom may be a bit of | |
53 # a hack, but it seems to work. | |
54 q="$(echo | dmenu)" | |
55 [ -z "$q" ] && exit 0 | |
56 | |
57 # Extract the engine code. | |
58 e="${q%% *}" | |
59 | |
60 # Encode the search string (i.e. the rest of q). xxd was formerl… | |
61 # here, but xxd is part of vim packages on some systems, whereas… | |
62 # ubiquitous. A search script that breaks if someone accidentall… | |
63 # vim is stupid. | |
64 s=$(printf %s "${q#* }" | tr -d '\n' | od -t x1 -An | tr ' ' '%… | |
65 | |
66 # These are examples. Change as desired. | |
67 # 's' = startpage.com | |
68 # 'w' = wikipedia.org | |
69 # 'a' = wiki.archlinux.org | |
70 # 'd' = en.wiktionary.org | |
71 case $e in | |
72 's') | |
73 xprop -id $1 -f _SURF_GO 8s -set _SURF_GO "https… | |
74 ;; | |
75 'w') | |
76 xprop -id $1 -f _SURF_GO 8s -set _SURF_GO "https… | |
77 ;; | |
78 'a') | |
79 xprop -id $1 -f _SURF_GO 8s -set _SURF_GO "https… | |
80 ;; | |
81 'd') | |
82 xprop -id $1 -f _SURF_GO 8s -set _SURF_GO "https… | |
83 ;; | |
84 *) | |
85 exit 1 | |
86 ;; | |
87 esac |