-
Notifications
You must be signed in to change notification settings - Fork 1
/
bang!
executable file
·170 lines (149 loc) · 6.34 KB
/
bang!
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#!/bin/sh -e
help() {
cat - >&2 <<EOF
This script emulates DuckDuckGo's "bangs" feature, but better:
1. Links are generated locally, which saves time, esp. on slow connections.
2. Fully configurable/extensible. New bangs can be defined in ~/.bangs,
described below. The default bang can also be changed with the DEFAULT_BANG
environment variable.
3. The generated links point to non-JS versions/mirrors of sites when available.
4. Links can be generated for non-HTTP resources, such as Gopher.
Examples:
bang! what is a cat?
bang! !w cat
bang! !wes gato # Spanish-Wikipedia page for cat
bang! !yt cat videos
Environment variables used by this script:
BROWSER: (default: xdg-open)
The command that will be used to open the link. You may want to set
this to your preferred web browser. Set to "echo" to just print the
link to standard output.
DEFAULT_BANG: (default: !duckduckgo)
The default bang if no bang is provided.
NITTER_MIRRORS:
Nitter mirrors used by !tw and !twitter, URLs must end with /
INVIDIOUS_MIRRORS:
Invidious mirrors used by !yt and !youtube, URLs must end with /
The ~/.bangs (or \$BANGS) file:
This file allows you to define your own bangs which take priority
over this script's builtin bangs. The location of the file can be
overriden with the \$BANG variable. Here's an example:
case "\$bang" in
!g) link="https://www.google.com/search?q=\$*" ;;
!a) link="https://www.amazon.com/s/?field-keywords=\$*" ;;
esac
EOF
}
case "$1" in
-h|--help) help; exit 0 ;;
'') exit 0 ;;
!*) bang="$1"; shift 1 ;;
*) bang="${DEFAULT_BANG:-!duckduckgo}" ;;
esac
if [ -r "${BANGS:=${HOME:?}/.bangs}" ]; then
. "$BANGS" "$@"
fi
# each URL must end with /
: ${NITTER_MIRRORS='https://bird.trom.tf/
https://birdsite.xanny.family/
https://n.0x0.st/
https://n.hyperborea.cloud/
https://nitter.1d4.us/
https://nitter.alefvanoon.xyz/
https://nitter.autarkic.org/
https://nitter.ca/
https://nitter.domain.glass/
https://nitter.eu/
https://nitter.fdn.fr/
https://nitter.grimneko.de/
https://nitter.ir/
https://nitter.it/
https://nitter.koyu.space/
https://nitter.mailstation.de/
https://nitter.moomoo.me/
https://nitter.namazso.eu/
https://nitter.net/
https://nitter.nixnet.services/
https://nitter.pussthecat.org/
https://nitter.unixfox.eu/
https://nitter.vxempire.xyz/
https://twitter.076.ne.jp/
https://twitter.censors.us/'}
# each URL must end with /
: ${INVIDIOUS_MIRRORS='https://invidious.namazso.eu/
https://vid.puffyan.us/
https://yewtu.be/
https://yt.artemislena.eu/'}
#
# these are sorted alphabetically, please try to maintain this
#
# in Vim you can sort this by putting your cursor on the first bang,
# C-v, and then putting cursor on the last bang, and then :sort
#
# each bang is restricted to one line so it's easier to sort
#
if [ ! "$link" ]; then
case "$bang" in
!alpine) link="https://pkgs.alpinelinux.org/packages?name=$*" ;;
!alpinewiki) link="https://wiki.alpinelinux.org/w/index.php?search=$*" ;;
!archaur|!aur) link="https://aur.archlinux.org/packages.php?K=$*" ;;
!archive) link="https://archive.org/search.php?query=$*" ;;
!archived|!wayback|!wb|!wbm) link="https://web.archive.org/web/*/$*" ;;
!archlinux) link="https://bbs.archlinux.org/search.php?keywords=$*" ;;
!archpkg|!archpackages) link="https://www.archlinux.org/packages/?q=$*" ;;
!aw|!arch|!archwiki) link="https://wiki.archlinux.org/index.php/$*" ;;
!a|!amazon) link="https://www.amazon.com/s/?field-keywords=$*" ;;
!ddg|!duckduckgo) link="https://duckduckgo.com/lite?q=$*" ;;
!deb) link="https://packages.debian.org/search?keywords=$*" ;;
!debian) link="https://search.debian.org/cgi-bin/omega?DB=en&P=$*" ;;
!e|!ebay) link="https://www.ebay.com/sch/i.html?_nkw=$*" ;;
!gb) link="https://www.google.com/search?q=$*&tbm=bks" ;;
!gentoopkg|!gentoopackage) link="https://packages.gentoo.org/packages/search?q=$*" ;;
!gentoo|!gentoowiki) link="https://wiki.gentoo.org/?search=$*" ;;
!gh|!github) link="https://github.com/search?q=$*" ;;
!gi) link="https://www.google.com/search?q=$*&tbm=isch" ;;
!gm) link="https://www.google.com/maps/search/$*" ;;
!gn) link="https://news.google.com/search?q=$*" ;;
!gp|!gw|!gopherpedia) link="gopher://gopherpedia.com/7/lookup%09$*?" ;;
!gs) link="https://www.google.com/search?q=$*&tbm=shop" ;;
!gt) link="https://translate.google.com/?text=$*" ;;
!gv) link="https://www.google.com/search?q=$*&tbm=video" ;;
!g|!google) link="https://www.google.com/search?q=$*" ;;
!hackage) link="https://hackage.haskell.org/packages/search?terms=$*" ;;
!hn|!hackernews) link="https://hn.algolia.com/?q=$*" ;;
!h|!hoogle) link="https://hoogle.haskell.org/?hoogle=$*" ;;
!imdb) link="https://www.imdb.com/find?q=$*" ;;
!lt|!limetorrents) IFS=-; link="https://www.limetorrents.pro/search/all/$*/" ;;
!lw|!legwork) link="http://legwork.i2p/yacysearch.html?query=$*" ;;
!man|!debman) link="https://manpages.debian.org/jump?q=$*" ;;
!nethack) link="https://nethackwiki.com/wiki/?search=$*" ;;
!nyaa) link="https://nyaa.si/?f=0&c=0_0&q=$*" ;;
!phoronix) link="https://www.phoronix.com/scan.php?page=search&q=$*" ;;
!pm|!postman) link="http://tracker2.postman.i2p/?search=$*" ;;
!p|!pinterest) link="https://www.pinterest.com/search/pins/?q=$*" ;;
!r|!reddit) link="https://old.reddit.com/search?q=$*" ;;
!so|!stackoverflow) link="https://stackoverflow.com/search?q=$*" ;;
!ste|!steam) link="https://store.steampowered.com/search/?term=$*" ;;
!tgb|!thegopherbay) link="gopher://bay.parazy.de:666/7/q.dcgi?%09$*" ;;
!tpb10|!thepiratebay10) link="https://thepiratebay10.org/search/$*" ;;
!tpbl|!piratebaylive) link="https://piratebay.live/search/$*" ;;
!tpb|!thepiratebay) link="https://thepiratebay.org/search.php?q=$*" ;;
!twitch) link="https://www.twitch.tv/$*" ;;
!twitchg) link="https://www.twitch.tv/directory/game/$*" ;;
!tw|!twitter) link="$(printf '%s\n' "$NITTER_MIRRORS" | shuf | head -n 1)search?q=$*" ;;
!v|!veronica) link="gopher://gopher.floodgap.com:70/7/v2/vs?%09$*" ;;
!w) link="https://wikipedia.org/w/index.php?search=$*&ns0=1" ;;
!w??) link="https://${bang#!w}.wikipedia.org/w/index.php?search=$*&ns0=1" ;;
!wa|!wolf|!wolfram) link="https://www.wolframalpha.com/input/?i=$*" ;;
!wt) link="https://wiktionary.org/wiki/$*" ;;
!wt??) link="https://${bang#!wt}.wiktionary.org/wiki/$*" ;;
!yt|!youtube) link="$(printf '%s\n' "$INVIDIOUS_MIRRORS" | shuf | head -n 1)search?q=$*" ;;
!zillow) link="https://www.zillow.com/homes/$*_rb" ;;
*)
printf '%s\n' "unknown bang $bang" >&2
help
exit 1
;;
esac
fi
eval exec "${BROWSER:-xdg-open}" '"$link"'