-
Notifications
You must be signed in to change notification settings - Fork 1
/
websearch
executable file
·94 lines (86 loc) · 2.21 KB
/
websearch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env bash
trap exit int
set -o nounset -o errexit
## search the web from the command line
BROWSER='firefox'
OPEN_IN='new tab'
BASEURL='https://www.duckduckgo.com/?q='
SEARCH_TERM_SOURCE="command line"
while getopts :agdmiysvwWTGFKx OPT; do
case $OPT in
a|+a)
BASEURL='http://adsabs.harvard.edu/cgi-bin/nph-basic_connect?qsearch='
;;
g|+g)
BASEURL='https://www.google.com/#q='
;;
d|+d)
BASEURL='https://www.duckduckgo.com/?q='
;;
m|+m)
BASEURL='http://maps.google.com/maps?q='
;;
i|+i)
BASEURL='https://www.google.com/search?hl=en&site=imghp&tbm=isch&q='
;;
y|+y)
BASEURL='https://www.youtube.com/results?search_query='
;;
v|+v)
BASEURL='http://translate.google.com/#sv|en|'
;;
s|+s)
BASEURL='http://scholar.google.com/scholar?q='
;;
w|+w)
BASEURL='http://en.wikipedia.org/wiki/'
;;
T|+T)
OPEN_IN='new tab'
;;
W|+W)
OPEN_IN='new window'
;;
G|+G)
BROWSER='chromium'
;;
F|+F)
BROWSER='firefox'
;;
K|+K)
BROWSER='konqueror'
;;
x|+x)
SEARCH_TERM_SOURCE="x selection"
;;
*)
echo "usage: ${0##*/} [+-agmiysvwWTGF} [--] SEARCH TERM..."
exit 2
esac
done
shift $(( OPTIND - 1 ))
OPTIND=1
case $SEARCH_TERM_SOURCE in
"command line")
SEARCH_TERM="$*"
;;
"x selection")
SEARCH_TERM=$(xclip -o)
;;
*)
exit 1
esac
BROWSER_ARGS=""
if [[ $BROWSER == 'chromium' ]] ; then
if [[ $OPEN_IN == 'new window' ]] ; then
BROWSER_ARGS="$BROWSER_ARGS --new-window"
fi
elif [[ $BROWSER == 'firefox' ]] ; then
if [[ $OPEN_IN == 'new window' ]] ; then
BROWSER_ARGS="$BROWSER_ARGS -new-window"
elif [[ $OPEN_IN == 'new tab' ]] ; then
BROWSER_ARGS="$BROWSER_ARGS -new-tab"
fi
fi
COMMAND="$BROWSER $BROWSER_ARGS '$BASEURL${SEARCH_TERM}'"
bash -c "$COMMAND"