rice

personal dot files and scripts for linux and macOS
Log | Files | Refs | README | LICENSE

surf_search (1568B)


      1 #!/bin/sh
      2 #
      3 # surf_qsearch:
      4 # Search script for surf. Takes the surf window id as argument.
      5 # POSIX compliant and GNU-free, I think.
      6 #
      7 # Add something like the following to your surf/config.(def.)h, replacing
      8 # surf_qsearch with the name of the file you've copied this code into:
      9 #
     10 # /* Quick searching. */
     11 # #define QSEARCH { \
     12 #     .v = (char *[]){"/bin/sh", "-c", "surf_qsearch $0 $1", winid, NULL } \
     13 # }
     14 #
     15 # Add a keybinding in keys[]:
     16 #
     17 # { MODKEY, GDK_q, spawn, QSEARCH },
     18 
     19 # Get the full query. The 'echo | dmenu' idiom may be a bit of
     20 # a hack, but it seems to work.
     21 q="$(echo | dmenu -c -h 50)"
     22 [ -z "$q" ] && exit 0
     23 
     24 # Extract the engine code.
     25 e="${q%% *}"
     26 
     27 # Encode the search string (i.e. the rest of q). xxd was formerly used
     28 # here, but xxd is part of vim packages on some systems, whereas od is
     29 # ubiquitous. A search script that breaks if someone accidentally removes
     30 # vim is stupid.
     31 s=$(printf %s "${q#* }" | tr -d '\n' | od -t x1 -An |  tr ' ' '%')
     32 # These are examples. Change as desired.
     33 # 's' = startpage.com
     34 # 'w' = wikipedia.org
     35 # 'a' = wiki.archlinux.org
     36 # 'd' = en.wiktionary.org
     37 case $e in
     38 	's')
     39 		xprop -id $1 -f _SURF_GO 8s -set _SURF_GO "https://startpage.com/do/search?q=${s}"
     40 		;;
     41 	'w')
     42 		xprop -id $1 -f _SURF_GO 8s -set _SURF_GO "https://en.wikipedia.org/wiki/index.php/Special:Search?search=${s}&go=Go"
     43 		;;
     44 	'a')
     45 		xprop -id $1 -f _SURF_GO 8s -set _SURF_GO "https://wiki.archlinux.org/index.php/Special:Search?search=${s}&go=Go"
     46 		;;
     47 	*)
     48 		xprop -id $1 -f _SURF_GO 8s -set _SURF_GO "https://duckduckgo.com/lite?q=${s}&"
     49 		;;
     50 esac