-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.py
executable file
·52 lines (42 loc) · 1.75 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
#!/usr/bin/env python3
import logging
import os
from datetime import datetime
class Symlink:
def __init__(self) -> None:
date = datetime.now().isoformat(timespec="seconds")
self.backup_dir = os.path.join(DOTFILES, "backup", date)
def make(self, src: str, dst: str) -> None:
if os.path.lexists(dst):
if os.path.realpath(dst) == src:
logger.info(f"OK {dst}")
return
os.makedirs(self.backup_dir, exist_ok=True)
backup = os.path.join(self.backup_dir, os.path.basename(dst))
os.rename(dst, backup)
logger.info(f"created {os.path.relpath(backup)}")
os.makedirs(os.path.dirname(dst), exist_ok=True)
os.symlink(src, dst)
logger.info(f"symlinked {dst} -> {src}")
def main():
symlink = Symlink()
for item in ["zshrc", "gnupg/gpg.conf", "gnupg/gpg-agent.conf"]:
src = os.path.join(DOTFILES, item)
dst = os.path.join(HOME, f".{item}")
symlink.make(src, dst)
for item in ["mpv", "wezterm", "zed"]:
src = os.path.join(DOTFILES, item)
dst = os.path.join(HOME, ".config", item)
symlink.make(src, dst)
is_darwin = os.uname().sysname == "Darwin"
for item in ["streamlink", "Code/User/keybindings.json", "Code/User/settings.json"]:
config_dir = "Library/Application Support" if is_darwin else ".config"
src = os.path.join(DOTFILES, item)
dst = os.path.join(HOME, config_dir, item)
symlink.make(src, dst)
if __name__ == "__main__":
logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s")
logger = logging.getLogger(__name__)
DOTFILES = os.path.dirname(os.path.abspath(__file__))
HOME = os.environ["HOME"]
main()