-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.py
52 lines (44 loc) · 1.32 KB
/
install.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
48
49
50
51
52
import pathlib
SKIP_LIST = (
'CMakeLists.txt',
'README.md',
'build',
'install.py',
'src',
)
def main():
replace_all = False
path = pathlib.Path('.')
for fn in path.glob("*"):
if fn.name.startswith('.') or fn.name in SKIP_LIST:
continue
fn = fn.resolve()
home_fn = path.home() / ('.' + fn.name)
if home_fn.is_symlink() or home_fn.exists():
if home_fn.exists() and home_fn.samefile(fn):
print(f'identical {home_fn}')
elif replace_all:
replace_file(home_fn, fn)
else:
answer = input(f'overwrite {home_fn}? [ynaq] ')
if answer == 'a':
replace_all = True
replace_file(home_fn, fn)
elif answer == 'y':
replace_file(home_fn, fn)
elif answer == 'q':
return
else:
link_file(home_fn, fn)
def replace_file(home_fn: pathlib.Path, fn: pathlib.Path):
if home_fn.is_dir():
# TODO: remove recursive
home_fn.rmdir()
else:
home_fn.unlink()
link_file(home_fn, fn)
def link_file(home_fn: pathlib.Path, fn: pathlib.Path):
print(f'ln -s {fn} {home_fn}')
home_fn.symlink_to(fn)
if __name__ == "__main__":
main()