-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
288 lines (244 loc) · 8.41 KB
/
Rakefile
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
require 'fileutils'
['pp','yaml'].each { |l| require l }
# Some helpful instance variables.
@home = File.expand_path "~"
@dotfiles_path = File.expand_path(File.dirname(__FILE__))
@paths = {
vim: {
bundle: File.join(@home, '.vim', 'bundle'),
backup: File.join(@home, '.vim', 'backup'),
scripts: File.join(@home, '.vim', 'scripts'),
colors: File.join(@home, '.vim', 'colors'),
},
sublime2: {
osx: File.join(@home, 'Library', 'Application Support', 'Sublime Text 2', 'Packages'),
},
sublime3: {
osx: File.join(@home, 'Library', 'Application Support', 'Sublime Text 3', 'Packages'),
},
zsh: {
scripts: File.join(@home, '.oh-my-zsh', 'custom'),
themes: File.join(@home, '.oh-my-zsh', 'themes'),
},
fish: {
base: File.join(@home, '.config', 'fish'),
},
rbenv: {
plugins: File.join(@home, '.rbenv', 'plugins'),
},
dropbox: {
root: File.join(@home, 'Dropbox'),
minecraft: File.join(@home, 'Dropbox', 'Personal', 'Games', 'Minecraft', 'Texture Packs'),
multimc: File.join(@home, 'Dropbox', 'Personal', 'Games', 'Minecraft'),
}
}
@urls = {
ohmyzsh: 'https://github.com/robbyrussell/oh-my-zsh',
benlight: 'https://gist.github.com/kreeger/6873818/raw/benlight.vim',
rbenv: {
rbenv: 'https://github.com/sstephenson/rbenv',
rubybuild: 'https://github.com/sstephenson/ruby-build',
},
}
# Directory setup declarations.
@paths.each { |top,hash| hash.each { |k,v| directory @paths[top][k] } }
task default: :all
task all: [:dotfiles, :vim, :fish]
# Base-level tasks.
desc 'Links all dotfiles into home directory.'
task :dotfiles do
# Gets all dotfiles in this directory, for each...
Dir['.*'].find_all{|f|File.file?(f)}.each do |f|
# ...link_files them into home unless the links already exist.
link_file File.expand_path(f), File.join(@home, f)
end
end
# Vim tasks.
desc 'Run all vim tasks.'
task vim: 'vim:all'
namespace :vim do
task all: [:vundle, :scripts, :colors]
desc 'Sets up Vim.'
task vundle: [:scripts, @paths[:vim][:bundle], @paths[:vim][:backup]] do
puts "Installing Vundle."
manage_git "git://github.com/gmarik/vundle.git",
File.join(@paths[:vim][:bundle], 'vundle')
system("vim +BundleInstall +qall > /dev/null 2&>1")
end
desc 'Installs all scripts from the vim directory.'
task scripts: @paths[:vim][:scripts] do
Dir.chdir File.join(@dotfiles_path,'vim')
Dir['*.vim'].each do |f|
puts "link_fileing custom Vim scripts."
link_file File.expand_path(f), File.join(@paths[:vim][:scripts], f)
end
end
desc 'Installs my color scheme(s).'
task colors: @paths[:vim][:colors] do
puts "Installing custom color scheme(s)."
destination = File.join(@paths[:vim][:colors], 'benlight.vim')
`curl -sko #{destination} #{@urls[:benlight]}`
end
end
desc 'Run all sublime 2 tasks.'
task sublime2: 'sublime2:all'
namespace :sublime2 do
task all: [:plugins, :settings]
# This is nearly identical to my Vim plugin installer; maybe abstract?
desc 'Install non-PackageManager plugins for sublime 2.'
task plugins: @paths[:sublime2][:osx] do
puts "Cloning extra plugins for Sublime Text 2."
plugins = load_yaml(File.join(@dotfiles_path, 'sublime.yml'), :plugins)
Dir.chdir(@paths[:sublime2][:osx])
plugins.each do |author, repos|
Array(repos).each do |repo|
manage_git "https://github.com/#{author}/#{repo[0]}",
File.join(@paths[:sublime2][:osx], repo[1])
end
end
end
desc 'Symlink sublime 2 settings.'
task settings: File.join(@paths[:sublime2][:osx], 'User') do
puts "Symlinking sublime 2 settings files."
Dir.chdir File.join(@dotfiles_path, 'sublime')
Dir['*.sublime-settings','*.sublime-keymap','*.sublime-mousemap','*.sublime-build','*.py'].each do |f|
link_file File.expand_path(f),
File.join(@paths[:sublime2][:osx], 'User', f)
end
end
end
desc 'Run all sublime 3 tasks.'
task sublime3: 'sublime3:all'
namespace :sublime3 do
task all: [:plugins, :settings]
# This is nearly identical to my Vim plugin installer; maybe abstract?
desc 'Install non-PackageManager plugins for sublime 3.'
task plugins: @paths[:sublime3][:osx] do
puts "Cloning extra plugins for Sublime Text 3."
plugins = load_yaml(File.join(@dotfiles_path, 'sublime.yml'), :plugins)
Dir.chdir(@paths[:sublime3][:osx])
plugins.each do |author, repos|
Array(repos).each do |repo|
manage_git "https://github.com/#{author}/#{repo[0]}",
File.join(@paths[:sublime3][:osx], repo[1])
end
end
end
desc 'Symlink sublime 3 settings.'
task settings: File.join(@paths[:sublime3][:osx], 'User') do
puts "Symlinking sublime 3 settings files."
Dir.chdir File.join(@dotfiles_path, 'sublime')
Dir['*.sublime-settings','*.sublime-keymap','*.sublime-snippet','*.sublime-mousemap','*.sublime-build','*.py'].each do |f|
link_file File.expand_path(f),
File.join(@paths[:sublime3][:osx], 'User', f)
end
end
end
# Zsh tasks.
desc 'Run all zsh tasks.'
task zsh: 'zsh:all'
namespace :zsh do
task all: [:ohmyzsh, :scripts, :themes]
desc 'Install ohmyzsh.'
task :ohmyzsh do
puts "Cloning oh-my-zsh."
manage_git @urls[:ohmyzsh], File.join(@home, '.oh-my-zsh')
end
desc 'Install custom zsh scripts.'
task scripts: @paths[:zsh][:scripts] do
puts "Symlinking in custom zsh scripts."
Dir.chdir File.join(@dotfiles_path,'zsh')
Dir['*'].reject { |e| e.match /^\./ }.each do |f|
link_file File.expand_path(f), File.join(@paths[:zsh][:scripts], f)
end
end
desc 'Install custom zsh themes.'
task themes: @paths[:zsh][:themes] do
puts "Symlinking in custom zsh themes."
Dir.chdir File.join(@dotfiles_path, 'zsh-themes')
Dir['*'].reject { |e| e.match /^\./ }.each do |f|
link_file File.expand_path(f), File.join(@paths[:zsh][:themes], f)
end
end
end
# Zsh tasks.
desc 'Run all fish tasks.'
task fish: 'fish:all'
namespace :fish do
task all: [:scripts]
desc 'Install custom fish scripts.'
task scripts: @paths[:fish][:base] do
puts "Symlinking in custom fish scripts."
Dir.chdir File.join(@dotfiles_path,'fish')
Dir['*'].reject { |e| e.match /^\./ }.each do |f|
link_file File.expand_path(f), File.join(@paths[:fish][:base], f)
end
end
end
# RBENV tasks.
desc 'Run all RBENV tasks.'
task rbenv: 'rbenv:all'
namespace :rbenv do
task all: [:install, :plugins]
desc 'Install rbenv.'
task :install do
puts "Installing rbenv."
Dir.chdir(@home)
manage_git @urls[:rbenv][:rbenv], File.join(@home, '.rbenv')
end
desc 'Install rbenv plugins.'
task :plugins do
puts "Cloning ruby-build."
manage_git @urls[:rbenv][:rubybuild], File.join(@home, 'ruby-build')
puts "Installing ruby-build."
Dir.chdir(File.join(@home, 'ruby-build'))
`sh install.sh`
Dir.chdir(@home)
puts "Removing temporary ruby-build directory."
FileUtils.rm_rf 'ruby-build'
end
end
desc 'Symlinks Dropbox to various places.'
task dropbox: 'dropbox:all'
namespace :dropbox do
task all: [:minecraft]
desc 'Symlink texture packs.'
task :minecraft do
puts "Symlinking minecraft texture packs."
destination = File.join(@home, 'Library', 'Application Support', 'minecraft', 'texturepacks')
debugger
link_file @paths[:dropbox][:minecraft], destination
end
desc 'Symlink MultiMC instance directory.'
task :multimc do
puts "Symlinking minecraft instances."
base = File.join('/Applications', 'MultiMC.app', 'Contents', 'Resources')
%w(Instances Mods lwjgl).each do |dir|
link_file File.join(@paths[:dropbox][:multimc], dir), File.join(base, dir.downcase)
end
end
end
# Some utility functions.
def load_yaml(path, key=nil)
yml = File.open(path, 'r') { |f| YAML::load f }
key.nil? ? yml : yml[key.to_s]
end
def link_file(source, destination)
# Delete the destination file if it exists, otherwise just link_file.
if File.exists?(destination)
File.directory?(destination) ? FileUtils.rm_r(destination) : File.delete(destination)
end
File.symlink(source, destination)
end
def manage_git(repo, destination)
# First check if it exists. If it does, do a git pull. Else, clone.
if File.exists? destination
puts "Found existing repo at #{destination}. Updating it."
Dir.chdir(destination)
`git pull`
Dir.chdir(File.join(destination, '..'))
else
puts "Repo #{repo} not found. Cloning to #{destination}."
`git clone #{repo} "#{destination}"`
end
end