[wiki] [sites] Added quick search script to surf.suckless.org/files || Wolfgang Corcoran-Mathe

From: <git_AT_suckless.org>
Date: Sat, 26 Jul 2014 18:34:00 +0200

commit 7bc6f2d8e08b2e33c66e4b36ec0641aa785c5d6e
Author: Wolfgang Corcoran-Mathe <first.lord.of.teal_AT_gmail.com>
Date: Sat Jul 26 12:29:34 2014 -0400

    Added quick search script to surf.suckless.org/files

diff --git a/surf.suckless.org/files/quick_search.md b/surf.suckless.org/files/quick_search.md
new file mode 100644
index 0000000..f831edd
--- /dev/null
+++ b/surf.suckless.org/files/quick_search.md
_AT_@ -0,0 +1,80 @@
+Quick searching with dmenu
+==================
+
+Description
+-----------
+
+Prompts for a query with dmenu and posts it to the selected search engine.
+The engine is specified by a single-character code that precedes the
+actual query, e.g. 'w pancakes' would search en.wikipedia.org for the string
+'pancakes'. This reduces the necessary shell plumbing to a couple of pipes
+and a case statement.
+
+Character ugliness in the query is avoided using xxd, tr, and sed. This
+has worked so far.
+
+Author
+------
+
+Wolfgang Corcoran-Mathe
+
+Installation
+------------
+
+Copy the following code into an executable file and place it in PATH. Edit
+surf/config.def.h as described in the header.
+
+Code
+----
+
+ #!/bin/sh
+ #
+ # surf_qsearch:
+ # Search engine script for surf. Takes the surf window id as argument.
+ # POSIX compliant and GNU-free, I think.
+ #
+ # Add something like the following to your surf/config.(def.)h, replacing
+ # surf_qsearch with the name of the file you've copied this code into:
+ #
+ # /* Quick searching. */
+ # #define QSEARCH { \
+ # .v = (char *[]){"/bin/sh", "-c", "surf_qsearch $0 $1", winid, NULL } \
+ # }
+ #
+ # Add a keybinding in keys[]:
+ #
+ # { MODKEY, GDK_q, spawn, QSEARCH },
+ #
+
+ # Get the full query. The 'echo | dmenu' idiom may be a bit of a hack.
+ q="$(echo | dmenu -p 'Search')"
+ [ -z "$q" ] && exit 0
+
+ # Extract the engine code.
+ e=$(printf %s "$q" | cut -c 1)
+
+ # Encode the search string (i.e. the rest of q)
+ s=$(printf %s "$q" | cut -c 3- | xxd -plain | tr -d '
' | sed 's/\(..\)/%/g')
+
+ # These are examples. Change as desired.
+ # 's' = startpage.com
+ # 'w' = wikipedia.org
+ # 'a' = wiki.archlinux.org
+ # 'd' = en.wiktionary.org
+ case $e in
+ 's')
+ xprop -id $1 -f _SURF_GO 8s -set _SURF_GO "https://startpage.com/do/search?q=${s}"
+ ;;
+ 'w')
+ xprop -id $1 -f _SURF_GO 8s -set _SURF_GO "https://en.wikipedia.org/wiki/index.php/Special:Search?search=${s}&go=Go"
+ ;;
+ 'a')
+ xprop -id $1 -f _SURF_GO 8s -set _SURF_GO "https://wiki.archlinux.org/index.php/Special:Search?search=${s}&go=Go"
+ ;;
+ 'd')
+ xprop -id $1 -f _SURF_GO 8s -set _SURF_GO "https://en.wiktionary.org/w/index.php?search=${s}&go=Go"
+ ;;
+ *)
+ exit 1
+ ;;
+ esac
Received on Sat Jul 26 2014 - 18:34:00 CEST

This archive was generated by hypermail 2.3.0 : Thu Jun 18 2015 - 17:39:28 CEST