-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsetup.py
73 lines (54 loc) · 2.11 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
#!/usr/bin/env python3
"""Sets up my dotfiles"""
from string import Template
from typing import Optional
import os
import subprocess
import shutil
PATHS = {'dot.emacs': '${HOME}/.emacs',
'dot.tmux.conf': '${HOME}/.tmux.conf',
'oh-my-zsh': '${HOME}/.oh-my-zsh',
'dot.vimrc': '${HOME}/.vimrc',
'dot.xmonad': '${HOME}/.xmonad',
'dot.zshrc': '${HOME}/.zshrc',
'dot.Xdefaults': '${HOME}/.Xdefaults',
'elisp': '${HOME}/elisp'}
PLUGINS = {'ale': "git clone --depth 1 https://github.com/dense-analysis/ale.git ~/.vim/pack/git-plugins/start/ale",
'zsh-dircolors-solarized': "git clone --recursive https://github.com/joel-porquet/zsh-dircolors-solarized ~/.oh-my-zsh/custom/plugins/zsh-dircolors-solarized"}
HOME = os.environ['HOME']
def _powershell_profile_path() -> Optional[str]:
ps_exe = shutil.which('powershell')
if ps_exe is None:
return None
return subprocess.run(
[ps_exe, os.path.join('t', 'GetPSProfilePath.ps1')],
stdout=subprocess.PIPE
).stdout.decode("utf-8").rstrip()
def _parse_and_copy(src: str, dest_tmpl: str):
dest_real = Template(dest_tmpl).substitute(HOME=HOME)
if os.path.lexists(dest_real):
print(dest_real + " already exists, skipping")
return
print(src + " => " + dest_real)
os.symlink(os.path.realpath(src), dest_real)
def setup_paths():
"""Creates symlinks"""
paths = PATHS
ps_profile_path = _powershell_profile_path()
if ps_profile_path is not None:
paths['dot.powershell.ps1'] = ps_profile_path
for origin, destination in PATHS.items():
if isinstance(destination, list):
for dest in destination:
_parse_and_copy(origin, dest)
else:
_parse_and_copy(origin, destination)
def install_plugins():
"""Install extra plugins"""
for plugin_name, install_cmd in PLUGINS.items():
install_return_code = os.system(install_cmd)
if install_return_code != 0:
print("error code was: %d" % install_return_code)
if __name__ == "__main__":
setup_paths()
install_plugins()