-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathset-links.py
executable file
·47 lines (36 loc) · 1.07 KB
/
set-links.py
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
"""
Helper script to set up ln -s <desired utilities> on a given bin/ PATH.
"""
import os
utilities = (
'images/scrap',
'mineutils/mc',
'misc/gitmail',
'misc/pipu',
'misc/reclick',
)
def run(program, *args):
"""Spawns a the given program as a subprocess and waits for its exit"""
# I for Invariant argument count, P for using PATH environmental variable
os.spawnlp(os.P_WAIT, program, program, *args)
if __name__ == '__main__':
where = None
try:
import pyperclip
where = pyperclip.paste()
if where.startswith('file://'):
where = where[len('file://'):]
if not os.path.isdir(where):
where = None
except ImportError:
pass
if not where:
where = input('Where should the links be created?\n: ')
if not os.path.isdir(where):
os.makedirs(where)
utilities = tuple(os.path.abspath(x) for x in utilities)
os.chdir(where)
for utility in utilities:
print(f'Creating link for {utility}...')
run('ln', '-s', utility)
print('Done!')