-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.py
executable file
·53 lines (40 loc) · 1.37 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
53
#!/usr/bin/python3
import datetime
import os
import shutil
import subprocess
import sys
def install_dot(src_path, dst_dir="~"):
print(f"\nInstalling {src_path} to {dst_dir}")
dst_dir = os.path.expanduser(dst_dir)
dst_path = os.path.join(dst_dir, src_path)
os.makedirs(os.path.dirname(dst_path), exist_ok=True)
if os.path.exists(dst_path):
with open(src_path) as src_file:
src_content = src_file.read()
with open(dst_path) as dst_file:
dst_content = dst_file.read()
if src_content == dst_content:
print(f" {dst_path} is identical to {src_path}, skipping")
return
print(" diff:")
os.system(f"diff --color -u {dst_path} {src_path}")
print("")
backup_path = (
f"{dst_path}.bak.{datetime.datetime.now().isoformat(timespec='seconds')}"
)
print(f" Backup {dst_path} to {backup_path}")
shutil.copy(dst_path, backup_path)
print(f" Copy {src_path} to {dst_path}")
shutil.copy(src_path, dst_path)
def main():
install_dot(".zshrc")
install_dot(".vimrc")
install_dot(".tmux.conf")
install_dot(".config/nvim/init.vim")
install_dot(".config/nvim/coc-settings.json")
install_dot(".gitconfig")
install_dot(".gitignore_global")
install_dot(".fzf.zsh")
if __name__ == "__main__":
sys.exit(main())