-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathb
More file actions
executable file
·38 lines (26 loc) · 887 Bytes
/
b
File metadata and controls
executable file
·38 lines (26 loc) · 887 Bytes
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
#!/usr/bin/env python3
import webbrowser
from sys import argv, exit, stderr
from os.path import join, expanduser, isfile
CONFIG_PATH = join(expanduser('~'), '.config', 'dbangs', 'bangs')
def warn(err):
print(err, file=stderr)
exit(2)
def main():
if len(argv) == 1:
warn('No arguments supplied')
if not isfile(CONFIG_PATH):
warn(f'No configuration file found. Make sure {CONFIG_PATH} exists')
for bang, url, param in (tuple(line.split()) for line in open(CONFIG_PATH, 'r')):
if argv[1] == bang:
text = url + (param if len(argv) >= 3 else '')
try:
webbrowser.open(
text.format(' '.join(argv[2:]))
)
exit(0)
except webbrowser.Error as e:
exit(f'Could not open: {e}')
else:
warn('Unknown bang.')
main()