[wiki] [sites] Edits to surf.suckless.org/files/quick_search.md || Wolfgang Corcoran-Mathe

From: <git_AT_suckless.org>
Date: Tue, 19 Aug 2014 18:30:10 +0200

commit 3bbef6a90471595937d30e7c9e52fa69e7eaf60a
Author: Wolfgang Corcoran-Mathe <first.lord.of.teal_AT_gmail.com>
Date: Tue Aug 19 12:30:00 2014 -0400

    Edits to surf.suckless.org/files/quick_search.md

diff --git a/surf.suckless.org/files/quick_search.md b/surf.suckless.org/files/quick_search.md
index f831edd..fe270d3 100644
--- a/surf.suckless.org/files/quick_search.md
+++ b/surf.suckless.org/files/quick_search.md
_AT_@ -10,9 +10,12 @@ 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
+Character ugliness in the query is avoided using od and tr. This
 has worked so far.
 
+**EDIT:** Replaced xxd with od and eliminated a sed pipe. Replaced cut pipes
+with sh variable expansion.
+
 Author
 ------
 
_AT_@ -30,31 +33,18 @@ 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 },
- #
+ # Search script for surf. Takes the surf window id as argument.
 
- # Get the full query. The 'echo | dmenu' idiom may be a bit of a hack.
- q="$(echo | dmenu -p 'Search')"
+ # Get the full query. The 'echo | dmenu' idiom may be a bit of
+ # a hack, but it seems to work.
+ q="$(echo | dmenu)"
         [ -z "$q" ] && exit 0
 
         # Extract the engine code.
- e=$(printf %s "$q" | cut -c 1)
+ e="${q%% *}"
 
         # Encode the search string (i.e. the rest of q)
- s=$(printf %s "$q" | cut -c 3- | xxd -plain | tr -d '
' | sed 's/\(..\)/%/g')
+ s=$(printf %s "${q#* }" | od -t x1 -An | tr -d '
' | tr ' ' '%')
 
         # These are examples. Change as desired.
         # 's' = startpage.com
Received on Tue Aug 19 2014 - 18:30:10 CEST

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