forked from chriskuehl/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.py
executable file
·87 lines (64 loc) · 1.79 KB
/
update.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
83
84
85
86
87
#!/usr/bin/env python3
import glob
import os
import sys
def exec(cmd, depth = 0):
print(("\t" * depth) + cmd)
os.system(cmd)
if len(sys.argv) > 1:
home = sys.argv[1]
if home.endswith("/"):
home = home[0:-1]
else:
home = os.path.expanduser("~")
use_rel_link = len(sys.argv) > 2
print("Target directory is: {}".format(home))
print("Updating submodules...")
exec("git submodule sync", 1)
exec("git submodule update --init", 1)
ocf = os.path.exists(home + "/.ocf")
special_cases = {
"terminalrc": ".config/Terminal/terminalrc",
"nvim-init.vim": ".config/nvim/init.vim",
}
print("Updating dotfiles...")
for file in glob.glob("*"):
if not file.endswith(".py") and not file == 'scripts':
path = home + "/." + file
if file in special_cases:
path = home + "/" + special_cases[file]
path_dir = os.path.dirname(path)
# make directories if necessary
if not os.path.exists(path_dir):
os.makedirs(path_dir)
print("\t{}".format(path))
if os.path.lexists(path):
os.remove(path)
from_path = (".dotfiles/" + file) if use_rel_link else os.path.abspath(file)
exec("ln -s {} {}".format(from_path, path), 2)
# leave me alone!
print("Getting rid of history files...")
histfiles = [
"lesshst", # why does my pager keep history...?
"grails_history",
"histfile",
"mysql_history",
"nano_history",
"sqlite_history",
"bash_history",
"zsh_history",
'python_history',
]
for histfile in histfiles:
path = home + "/." + histfile
print("\t" + path)
if os.path.exists(path):
os.remove(path)
exec("ln -s /dev/null {}".format(path), 2)
# handle special cases
exec("touch {}/.mutt/muttrc-local".format(home))
exec("touch {}/.tmux-local.conf".format(home))
# are we on ocf?
if ocf:
exec("rm {}/.gitconfig".format(home))
exec("ln -s {}/.gitconfig-ocf {}/.gitconfig".format(home, home))