-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.rb
executable file
·194 lines (156 loc) · 4.01 KB
/
init.rb
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#!/bin/env ruby
require 'os'
unless File.exist?('./occupy.rb')
puts 'need the occupy.rb library'
exit(1)
# get occupy gem
end
require './occupy.rb'
unless ARGV[0] != ''
puts USAGE
exit(1)
end
# InitFramework.new takes 2 arguments
# - you can change the dotdir location (default: ~/.dotfiles)
# - and the config dir location (default: ~/.config)
init = InitFramework.new
# START of COMPONENTS
InitModule.new('dotfiles') do |dot|
dot.shell('git submodule update --init')
init.register(dot)
end
InitModule.new('homebrew') do |brew|
unless OS.mac?
kara.report_warning "Not a mac! Skipping..."
return
end
brew.shell("eval #{init.dotdir}/install/brew/install")
brew.shell('brew update')
brew.shell('brew upgrade')
brew.shell('brew bundle')
init.register(brew)
end
InitModule.new('git') do |git|
git.links = [
InitLink.new(init, 'git/gitconfig', Dir.home + '/.gitconfig'),
InitLink.new(init, 'git/gitignore_global', Dir.home + '/.gitignore_global')
]
git.shell('git config --global core.excludesfile $HOME/.gitignore_global')
init.register(git)
end
InitModule.new('vim') do |vim|
vim.needs_dir = [
init.dotdir + '/vim/backups',
init.dotdir + '/vim/swaps',
init.dotdir + '/vim/undo',
init.dotdir + '/vim/autoload/plug.vim'
]
vim.links = [
InitLink.new(init, 'vim', Dir.home + '/.vim'),
InitLink.new(init, 'vim', init.configdir + '/nvim')
]
# update vim-plug
vim.shell('$(which nvim) +PlugUpdate +:qall')
init.register(vim)
end
InitModule.new('ctags') do |tags|
tag.links = [
InitLink.new(init, 'ctags/ctags', Dir.home + '/.ctags')
]
init.register(tags)
end
InitModule.new('zsh') do |zsh|
zsh.links = [
InitLink.new(init, 'zsh/zshrc', init.dotdir + '/zsh/.zshrc'),
InitLink.new(init, 'zsh/zshenv', init.dotdir + '/.zshenv'),
InitLink.new(init, 'zsh/zshenv', Dir.home + '/.zshenv')
]
init.register(zsh)
end
InitModule.new('tmux') do |tmux|
tmux.links = [
InitLink.new(init, 'tmux', Dir.home + '/.tmux'),
InitLink.new(init, 'tmux/tmux.conf', Dir.home + '/.tmux.conf'),
]
init.register(tmux)
end
InitModule.new('config') do |config|
config.links = []
apps = ['mpv', 'livestreamer', 'youtube-dl', 'bitbar']
apps.each do |a|
config.links << InitLink.new(init, a, init.configdir + '/' + a)
end
init.register(config)
end
InitModule.new('osx') do |osx|
unless OS.mac?
kara.report_warning "Not a mac! Skipping..."
return
end
osx.shell("eval #{init.dotdir}/osx/defaults.sh")
osx.shell("eval #{init.dotdir}/osx/dock.sh")
init.register(osx)
end
InitModule.new('hammerspoon') do |hs|
hs.links = [
InitLink.new(init, 'hammerspoon', Dir.home + '/.hammerspoon')
]
init.register(hs)
end
InitModule.new('porcelain') do |porc|
ver = "0.3.1"
platform = "linux_amd64"
if OS.mac?
platform = "darwin_amd64"
end
porc.shell("curl -L https://github.com/robertgzr/porcelain/releases/download/v#{ver}/porcelain_#{platform}.tar.gz | tar xz && mv -fv ./porcelain /usr/local/bin/porcelain")
unless porc.shell('which porcelain')
porc.report_warning "Couldn't find 'porcelain'!\nInstall went wrong..."
end
init.register(porc)
end
InitModule.new('karabiner') do |kara|
unless OS.mac?
kara.report_warning "Not a mac! Skipping..."
return
end
karadir = Dir.home + '/Library/Application Support/Karabiner'
if Dir.exist?(karadir)
if File.exist?(karadir + 'private.xml')
kara.links = [
InitLink.new(init, 'osx/karabiner/private.xml', karadir)
]
end
else
kara.report_warning 'Karabiner not installed?'
end
init.register(kara)
end
# END of COMPONENTS
USAGE = %(Usage: ./init.rb [run | dry | test] <module>
run\t install everything
dry\t show what it is going to install
test\t test the system
).freeze
case ARGV[0]
when 'dry'
if ARGV[1]
init.dry_run(ARGV[1])
else
init.dry_run
end
when 'run'
if ARGV[1]
init.run(ARGV[1])
else
init.run
end
when 'test'
if ARGV[1]
init.test(ARGV[1])
else
init.test
end
else
puts USAGE
end