master hovercats/bin / rc / dsearch
 1#!/bin/rc
 2
 3flag e +
 4
 5fn usage {printf 'Usage: dsearch -b|-d|-s|-y <query>\n' && exit 1}
 6
 7# Use dmenu to enter our search query
 8fn string {printf '' | dmenu -p 'Search'}
 9
10# search engine string
11DDG='https://lite.duckduckgo.com/html?q='
12SP='https://www.startpage.com/sp/search?query='
13BC='https://bandcamp.com/search?q='
14YT='https://inv.nadeko.net/search?q='
15
16switch($1) {
17	case -b
18		ENGINE=$BC
19		STRING=`{string | sed 's/ /%2B/g'} # Replace spaces
20	case -d
21		ENGINE=$DDG
22		STRING=`{string | sed 's/ /%20/g'} # Replace spaces
23	case -s
24		ENGINE=$SP
25		STRING=`{string | sed 's/ /%20/g'} # Replace spaces
26	case -y
27		ENGINE=$YT
28		STRING=`{string | sed 's/ /+/g'}   # Replace spaces
29	case *
30		usage
31}
32
33# Exit if our search query is empty
34if (~ $#STRING 0) usage
35
36exec $BROWSER $ENGINE$STRING