-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall
More file actions
executable file
·88 lines (75 loc) · 2.45 KB
/
install
File metadata and controls
executable file
·88 lines (75 loc) · 2.45 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
82
83
84
85
86
87
88
#!/usr/bin/env python3
import os
import shutil
from typing import List, TypedDict
usr_home = os.environ["HOME"]
CONFIG = {
"nvim": "$HOME/.config/nvim",
"bash": "$HOME",
"zsh": "$HOME/.config/zsh",
"tmux": "$HOME",
"profile": "$HOME",
"alacritty": "$HOME/.config/alacritty",
"zathura": "$HOME/.config/zathura",
"qtile": "$HOME/.config/qtile",
"xmonad": "$HOME/.xmonad",
"bin": "$HOME/.bin",
"vifm": "$HOME/.config/vifm",
}
config = CONFIG.keys()
map_location = list(map(lambda x: x.replace("$HOME", usr_home), CONFIG.values()))
link_map = dict(zip(config, map_location))
class source_destination_pair(TypedDict):
src: str
dest: str
def symlink(src: str, dest: str) -> None:
try:
readlink = os.readlink(dest)
except (FileNotFoundError, OSError):
readlink = False
if readlink:
if readlink == src:
print("[*] Already linked {} with {}".format(src, dest))
else:
if (
input(
"[+] Delete already linked {} with {} [y/N] ".format(src, readlink)
)
== "Y"
):
os.unlink(dest)
os.symlink(src, dest)
print("[*] linked {} with {}".format(src, dest))
else:
if os.path.exists(dest):
if input("[+] Delete {} [y/N] ".format(dest)) == "Y":
if os.path.isdir(dest):
shutil.rmtree(dest, ignore_errors=True)
else:
os.remove(dest)
os.symlink(src, dest)
print("[*] linked {} with {}".format(src, dest))
else:
os.symlink(src, dest)
print("[*] linked {} with {}".format(src, dest))
def get_map_for_link_in_home_dir(src, dest) -> List[source_destination_pair]:
return_list = []
for x in os.listdir(src):
_tmp_map = {}
_tmp_map["src"] = src + "/" + x
_tmp_map["dest"] = dest + "/" + x
return_list.append(_tmp_map)
return return_list
def main() -> None:
print("[*] symlinking ...")
for (src, dest) in link_map.items():
full_src_path = os.getcwd() + "/" + src
if dest == usr_home:
for _map in get_map_for_link_in_home_dir(full_src_path, dest):
_src, _dest = _map.values()
symlink(_src, _dest)
else:
symlink(full_src_path, dest)
print("[*] (done)")
if __name__ == "__main__":
main()