-
Notifications
You must be signed in to change notification settings - Fork 5
/
bootstrap.py
executable file
·156 lines (126 loc) · 2.57 KB
/
bootstrap.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/usr/bin/env python
import argparse
import os
import subprocess
DRY_RUN = False
BASE_PATH = os.path.dirname(os.path.realpath(__file__))
HOME = os.environ['HOME']
NOPES = (
'bin',
'srv',
'src',
'etc',
'bootstrap.py',
'project',
'plan',
'CHANGELOG.md',
'README.md'
)
NONS = (
'bin',
'srv',
'src',
'etc',
)
HARDS = (
'project',
'plan',
)
def doit(cmd):
"""
Exec a command
"""
print(' '.join(cmd))
if not DRY_RUN:
print(subprocess.check_output(cmd))
def link_dotfiles():
"""
Link all the dotfiles worth linking
"""
dirname, files, dirs = os.walk(BASE_PATH).next()
dots = files + dirs
for dot in [dot for dot in dots if dot not in NOPES]:
if dot.startswith('.'):
continue
cmd = ['ln', '-sfT']
cmd.append(os.path.join(dirname, dot))
cmd.append(os.path.join(HOME, '.%s' % dot))
doit(cmd)
def link_nondotfiles():
"""
For dem non dots
"""
for dot in NONS:
cmd = ['ln', '-sfT']
cmd.append(os.path.join(BASE_PATH, dot))
cmd.append(os.path.join(HOME, dot))
doit(cmd)
def hardlink_plans():
"""
.plan and .project. Link 'em.
"""
for hard in HARDS:
cmd = ['ln', '-f']
cmd.append(os.path.join(BASE_PATH, hard))
cmd.append(os.path.join(HOME, '.%s' % hard))
doit(cmd)
def submodules():
"""
Why do I do this to my dotties?
"""
cmd = [
'/usr/bin/git',
'-C',
BASE_PATH,
'submodule',
'update',
'--init',
'--recursive'
]
doit(cmd)
def vimshit():
"""
Do dat vim shit
"""
cmd = [
'/usr/bin/vim',
'+PluginInstall',
'+qall'
]
doit(cmd)
def base16shit():
"""
Do dat base16 shit
...is this better than submodules?
"""
cmd = [
'/usr/bin/git',
'clone',
'https://github.com/chriskempson/base16-shell.git',
os.path.join(HOME, '.config', 'base16-shell')
]
doit(cmd)
def parse_args():
"""
I thought I could get away without it, but I can't
"""
global DRY_RUN
ap = argparse.ArgumentParser('Setup muh dotfiles')
ap.add_argument(
'-t',
'--test',
action='store_true',
help='Dry run')
args = ap.parse_args()
if args.test:
DRY_RUN = True
def main():
parse_args()
link_dotfiles()
link_nondotfiles()
hardlink_plans()
submodules()
vimshit()
base16shit()
if __name__ == '__main__':
main()