-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbangs
More file actions
executable file
·81 lines (68 loc) · 1.83 KB
/
bangs
File metadata and controls
executable file
·81 lines (68 loc) · 1.83 KB
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
#! /bin/sh
# Todo: add option to pass stuff via args
if [ "$1" = "--help" ] || [ "$1" = "-h" ] || [ "$1" = "help" ]; then
printf "$ bangs
Portable custom duckduckgo bangs (tpb, lg, etc.)
Open in \$BROWSER ($BROWSER).
Bangs not in the list will be referred to duckduckgo.
Should be run via keyboard shortcut.
Commands:
list: list all available bangs
BANG QUERY: open the given query for the given bang
Examples:
$ bangs
$ bangs list
$ bangs yt 'rofi showcase'
"; exit
fi
MAIN_BROWSER=firefox
SECONDARY_BROWSER=firefox
hash rofi $MAIN_BROWSER $SECONDARY_BROWSER node || exit 127
DEFAULT_BANG="-" # ddg
bangList() {
cat $(dirname $0)/banglist
}
if [ "$1" = "list" ]; then
bangList
exit 0
fi
prompt() {
rofi -dmenu -l 0 -theme-str 'window {width: 300px;}' -p \!
}
urlEncode() {
node -e "console.log( encodeURIComponent( process.argv[1] ) )" "$1"
}
if [ -z "$2" ]; then
res="$(prompt)"
[ -z "$res" ] && exit 1
bang="${res%% *}"
rawquery="${res#* }"
[ "$query" = "$bang" ] && bang=$DEFAULT_BANG
else
bang=$1
rawquery="$2"
fi
query=`urlEncode "$rawquery"`
case "$bang" in
y)
~/scripts/yt $rawquery
exit;;
yts)
~/scripts/yts $rawquery
exit;;
13|nyaa|yy|j)
bangList | grep -m 1 "^$bang " | cut -d\ -f2- | sed "s|\%s|$query|" | xargs -r -0 $SECONDARY_BROWSER >/dev/null 2>&1 &
exit;;
rap)
$SECONDARY_BROWSER "https://duckduckgo.com/?q=!$bang%20$query" >/dev/null 2>&1 &
exit;;
esac
if bangList | grep -m 1 "^$bang " >/dev/null; then
bangList | grep -m 1 "^$bang " | cut -d\ -f2- | sed "s|\%s|$query|" | xargs -r -0 $MAIN_BROWSER >/dev/null 2>&1 &
else
if [ "$bang" = "$DEFAULT_BANG" ] && [ "$DEFAULT_BANG" = "-" ]; then
$MAIN_BROWSER "https://duckduckgo.com/?q=$query" >/dev/null 2>&1 &
else
$MAIN_BROWSER "https://duckduckgo.com/?q=!$bang%20$query" >/dev/null 2>&1 &
fi
fi