index.md - sites - public wiki contents of suckless.org
(HTM) git clone git://git.suckless.org/sites
(DIR) Log
(DIR) Files
(DIR) 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 engine.
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 string
10 'pancakes'. This reduces the necessary shell plumbing to a couple of pipes
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 pipes
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. Edit
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, replacing
40 # surf_qsearch with the name of the file you've copied this code into:
41 #
42 # /* Quick searching. */
43 # #define QSEARCH { \
44 # .v = (char *[]){"/bin/sh", "-c", "surf_qsearch $0 $1", winid, NULL } \
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 formerly used
61 # here, but xxd is part of vim packages on some systems, whereas od is
62 # ubiquitous. A search script that breaks if someone accidentally removes
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://startpage.com/do/search?q=${s}"
74 ;;
75 'w')
76 xprop -id $1 -f _SURF_GO 8s -set _SURF_GO "https://en.wikipedia.org/wiki/index.php/Special:Search?search=${s}&go=Go"
77 ;;
78 'a')
79 xprop -id $1 -f _SURF_GO 8s -set _SURF_GO "https://wiki.archlinux.org/index.php/Special:Search?search=${s}&go=Go"
80 ;;
81 'd')
82 xprop -id $1 -f _SURF_GO 8s -set _SURF_GO "https://en.wiktionary.org/w/index.php?search=${s}&go=Go"
83 ;;
84 *)
85 exit 1
86 ;;
87 esac