forked from drewolson/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
executable file
·82 lines (70 loc) · 2.45 KB
/
setup.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
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
#!/usr/bin/python3
import sys
import os
from pathlib import Path
# Setup common paths.
dotfiles_dir = Path(__file__).resolve().parent
# Ensure we execute from the dotfiles directory.
os.chdir(dotfiles_dir)
class ConfigFile:
def __init__(self, source, target):
self.source = Path(dotfiles_dir, source)
self.target = Path(Path.home(), target)
universal = [
ConfigFile("zshrc", Path(".zshrc")),
ConfigFile("zprofile", Path(".zprofile")),
ConfigFile("vimrc", Path(".vimrc")),
ConfigFile("ideavimrc", Path(".ideavimrc")),
ConfigFile("vim", Path(".vim")),
ConfigFile("tmux.conf", Path(".tmux.conf")),
ConfigFile("base16-shell", Path(".config", "base16-shell")),
ConfigFile("gitignore", Path(".gitignore")),
ConfigFile("gitconfig", Path(".gitconfig")),
ConfigFile("alacritty.toml", Path(".alacritty.toml")),
]
macos = []
linux = []
def link(config_files):
for config_file in config_files:
if not config_file.source.exists():
print(f"Missing source file {config_file.source}")
continue
if config_file.target.exists():
if config_file.target.resolve() == config_file.source:
print(f"Skipping {config_file.target}, already set correctly.")
continue
else:
print(f"Found existing {config_file.target} that doesn't match. Unlinking.")
config_file.target.unlink()
target_dir = Path(*config_file.target.parts[:-1])
if not target_dir.exists():
print(f"Creating new directory {target_dir}.".format(target_dir))
target_dir.mkdir(parents=True)
print(f"Linking {config_file.source} -> {config_file.target}.")
config_file.target.symlink_to(config_file.source)
def setup():
#
# Ensure submodules are initialized.
#
print("Checking submodules.")
if not Path(dotfiles_dir, "base16-shell", "README.md").exists():
print("Submodules are not initialized. Initializing.")
os.system("git submodule init")
os.system("git submodule update")
#
# Create symlinks.
#
print("Creating symlinks.")
link(universal)
if sys.platform.startswith("darwin"):
link(macos)
else:
link(linux)
#
# Setup basic tools on macos.
#
if sys.platform.startswith("darwin"):
print("Installing basic tools.")
os.system("brew install git tmux vim fzf")
if __name__ == "__main__":
setup()