forked from brakmic-aleksandar/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install
executable file
·49 lines (36 loc) · 1.37 KB
/
install
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
#!/usr/bin/env python3
import pathlib
from pathlib import os
SUCCESS_GREEN = '\u001b[32m'
OK_BLUE = '\033[94m'
WARNING_YELLOW = '\033[93m'
END_COLOR = '\033[0m'
def install_dir(src_files, dst_dir):
for src in src_files:
dst = dst_dir/src.name
if dst.resolve() == src:
print(f"{OK_BLUE}info:{END_COLOR} {dst} is already linked correctly, skipping.")
continue
if dst.exists():
dst_suffix = dst.with_suffix(".backup")
dst.rename(dst_suffix)
print(f"{WARNING_YELLOW}warning:{END_COLOR} {dst} already exists, it was renamed to {dst_suffix}.")
dst.symlink_to(src)
print(f"{SUCCESS_GREEN}success:{END_COLOR} {dst} installed successfully.")
home_dir = pathlib.Path.home()
xdg_config_home = os.getenv("XDG_CONFIG_HOME")
config_dir = pathlib.Path(xdg_config_home) if xdg_config_home else home_dir/".config"
script_home_dir = pathlib.Path(os.path.dirname(os.path.realpath(__file__)))
script_config_dir = script_home_dir/".config"
ignored_home_files = {
script_home_dir/".git",
script_home_dir/".gitignore",
script_home_dir/".gitattributes",
script_home_dir/"install",
script_home_dir/"README.md",
script_home_dir/".config"
}
home_files = list(filter(lambda file: file.resolve() not in ignored_home_files, script_home_dir.glob('*')))
config_files = list(script_config_dir.glob("*"))
install_dir(home_files, home_dir)
install_dir(config_files, config_dir)