-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRakefile
More file actions
379 lines (331 loc) · 9.43 KB
/
Copy pathRakefile
File metadata and controls
379 lines (331 loc) · 9.43 KB
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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
def brew_install(package, *args)
versions = `brew list #{package} --versions`
options = args.last.is_a?(Hash) ? args.pop : {}
# if brew exits with error we install tmux
if versions.empty?
sh "brew install #{package} #{args.join ' '}"
elsif options[:requires]
# brew did not error out, verify tmux is greater than 1.8
# e.g. brew_tmux_query = 'tmux 1.9a'
installed_version = versions.split(/\n/).first.split(' ')[1]
unless version_match?(options[:version], installed_version)
sh "brew upgrade #{package} #{args.join ' '}"
end
end
end
def version_match?(requirement, version)
# This is a hack, but it lets us avoid a gem dep for version checking.
Gem::Dependency.new('', requirement).match?('', version)
end
def install_github_bundle(user, package)
unless File.exist? File.expand_path("~/.vim/bundle/#{package}")
sh "git clone https://github.com/#{user}/#{package} ~/.vim/bundle/#{package}"
end
end
def step(description)
description = "-- #{description} "
description = description.ljust(80, '-')
puts
puts "\e[32m#{description}\e[0m"
end
def app_path(name)
path = "/Applications/#{name}.app"
["~#{path}", path].each do |full_path|
return full_path if File.directory?(full_path)
end
return nil
end
def app?(name)
return !app_path(name).nil?
end
def get_backup_path(path)
number = 1
backup_path = "#{path}.bak"
loop do
if number > 1
backup_path = "#{backup_path}#{number}"
end
if File.exists?(backup_path) || File.symlink?(backup_path)
number += 1
next
end
break
end
backup_path
end
def link_file(original_filename, symlink_filename)
original_path = File.expand_path(original_filename)
symlink_path = File.expand_path(symlink_filename)
if File.exists?(symlink_path) || File.symlink?(symlink_path)
if File.symlink?(symlink_path)
symlink_points_to_path = File.readlink(symlink_path)
return if symlink_points_to_path == original_path
# Symlinks can't just be moved like regular files. Recreate old one, and
# remove it.
ln_s symlink_points_to_path, get_backup_path(symlink_path), :verbose => true
rm symlink_path
else
# Never move user's files without creating backups first
mv symlink_path, get_backup_path(symlink_path), :verbose => true
end
end
ln_s original_path, symlink_path, :verbose => true
end
def unlink_file(original_filename, symlink_filename)
original_path = File.expand_path(original_filename)
symlink_path = File.expand_path(symlink_filename)
if File.symlink?(symlink_path)
symlink_points_to_path = File.readlink(symlink_path)
if symlink_points_to_path == original_path
# the symlink is installed, so we should uninstall it
rm_f symlink_path, :verbose => true
backups = Dir["#{symlink_path}*.bak"]
case backups.size
when 0
# nothing to do
when 1
mv backups.first, symlink_path, :verbose => true
else
$stderr.puts "found #{backups.size} backups for #{symlink_path}, please restore the one you want."
end
else
$stderr.puts "#{symlink_path} does not point to #{original_path}, skipping."
end
else
$stderr.puts "#{symlink_path} is not a symlink, skipping."
end
end
namespace :install do
desc 'Update or Install Brew'
task :brew do
step 'Homebrew'
unless system('which brew > /dev/null || ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"')
raise "Homebrew must be installed before continuing."
end
end
desc 'Install Git'
task :git do
step 'git'
brew_install 'git'
end
desc 'Install cmake'
task :cmake do
step 'cmake'
brew_install 'cmake'
end
desc 'Install ctags'
task :ctags do
step 'ctags'
sh 'brew tap universal-ctags/universal-ctags'
brew_install 'universal-ctags', ['--HEAD']
end
desc 'Install cscope'
task :cscope do
step 'cscope'
brew_install 'cscope'
end
desc 'Install The Silver Searcher'
task :the_silver_searcher do
step 'the_silver_searcher'
brew_install 'the_silver_searcher'
end
desc 'Install reattach-to-user-namespace'
task :reattach_to_user_namespace do
step 'reattach_to_user_namespace'
brew_install 'reattach-to-user-namespace'
end
desc 'Install tmux'
task :tmux do
step 'tmux'
brew_install 'tmux', ['--HEAD']
end
desc 'Install Zsh'
task :zsh do
step 'zsh'
brew_install 'zsh'
end
desc 'Install Python 2'
task :python2 do
step 'python2'
brew_install 'python'
end
desc 'Install Python 3'
task :python3 do
step 'python3'
brew_install 'python3'
end
desc 'Install Vim'
task :vim do
step 'vim'
brew_install 'vim', ['--override-system-vi', '--with-lua', '--HEAD']
end
desc 'Install MacVim'
task :macvim do
step 'macvim'
brew_install 'macvim', ['--with-lua', '--custom-icons']
end
desc 'Install Neovim'
task :neovim do
step 'neovim'
sh "brew tap cHoco/homebrew-formula"
brew_install 'neovim', ['--HEAD']
end
desc 'Install Neofetch'
task :neofetch do
step 'neofetch'
brew_install 'neofetch'
end
desc 'Install mono'
task :mono do
step 'mono'
brew_install 'mono'
end
desc 'Install OpenGL support libraries'
task :opengl_support_libs do
step 'opengl_support_libs'
sh "brew tap homebrew/versions"
brew_install 'glm'
brew_install 'glfw3'
brew_install 'glew'
brew_install 'assimp'
end
desc 'Install aspell'
task :aspell do
step 'aspell'
brew_install 'aspell', ['--with-lang-en', '--with-lang-it', '--devel']
end
desc 'Install weechat'
task :weechat do
step 'weechat'
brew_install 'weechat', ['--with-aspell', '--with-lua', '--with-perl', '--with-python', '--with-ruby']
end
desc 'Install Vim Plugins'
task :vim_plugins do
step 'vim_plugins'
sh 'nvim +PlugInstall +qall'
end
end
def filemap(map)
map.inject({}) do |result, (key, value)|
result[File.expand_path(key)] = File.expand_path(value)
result
end.freeze
end
COPIED_FILES = filemap(
'vimrc.local' => '~/.vimrc.local',
'vimrc.bundles.local' => '~/.vimrc.bundles.local',
'tmux.conf.local' => '~/.tmux.conf.local'
)
VIM_FILES = filemap(
'vim' => '~/.vim',
'vimrc' => '~/.vimrc',
)
NVIM_FILES = filemap(
'vim' => '~/.config/nvim',
'vimrc' => '~/.config/nvim/init.vim'
)
GIT_FILES = filemap(
'git/gitconfig' => '~/.gitconfig',
'git/gitignore_global' => '~/.gitignore_global'
)
ZSH_FILES = filemap(
'zsh/zlogin' => '~/.zlogin',
'zsh/zlogout' => '~/.zlogout',
'zsh/zpreztorc' => '~/.zpreztorc',
'zsh/zprofile' => '~/.zprofile',
'zsh/zshenv' => '~/.zshenv',
'zsh/zshrc' => '~/.zshrc'
)
KWM_FILES = filemap(
'kwm' => '~/.kwm',
'kwm/com.koekeishiya.kwm.plist' => '~/Library/LaunchAgents/com.koekeishiya.kwm.plist'
)
KHD_FILES = filemap(
'khd/khdrc' => '~/.khdrc',
'khd/com.koekeishiya.khd.plist' => '~/Library/LaunchAgents/com.koekeishiya.khd.plist'
)
OTHER_FILES = filemap(
'tmux.conf' => '~/.tmux.conf',
'ssh/config' => '~/.ssh/config',
'weechat' => '~/.weechat'
)
desc 'Install these config files.'
task :install do
#Rake::Task['install:brew'].invoke
#Rake::Task['install:git'].invoke
#Rake::Task['install:cmake'].invoke
#Rake::Task['install:ctags'].invoke
#Rake::Task['install:cscope'].invoke
#Rake::Task['install:the_silver_searcher'].invoke
#Rake::Task['install:reattach_to_user_namespace'].invoke
#Rake::Task['install:tmux'].invoke
#Rake::Task['install:zsh'].invoke
#Rake::Task['install:python2'].invoke
#Rake::Task['install:python3'].invoke
#Rake::Task['install:vim'].invoke
#Rake::Task['install:macvim'].invoke
#Rake::Task['install:neovim'].invoke
#Rake::Task['install:neofetch'].invoke
#Rake::Task['install:mono'].invoke
#Rake::Task['install:opengl_support_libs'].invoke
#Rake::Task['install:aspell'].invoke
#Rake::Task['install:weechat'].invoke
step 'symlink'
VIM_FILES.each do |orig, link|
link_file orig, link
end
mkdir_p File.expand_path('~/.config')
NVIM_FILES.each do |orig, link|
link_file orig, link
end
GIT_FILES.each do |orig, link|
link_file orig, link
end
ZSH_FILES.each do |orig, link|
link_file orig, link
end
# KWM_FILES.each do |orig, link|
# link_file orig, link
# end
KHD_FILES.each do |orig, link|
link_file orig, link
end
OTHER_FILES.each do |orig, link|
link_file orig, link
end
# COPIED_FILES.each do |orig, copy|
# cp orig, copy, :verbose => true unless File.exist?(copy)
# end
#Rake::Task['install:vim_plugins'].invoke
end
desc 'Uninstall these config files.'
task :uninstall do
step 'un-symlink'
# un-symlink files that still point to the installed locations
VIM_FILES.each do |orig, link|
unlink_file orig, link
end
NVIM_FILES.each do |orig, link|
unlink_file orig, link
end
GIT_FILES.each do |orig, link|
unlink_file orig, link
end
ZSH_FILES.each do |orig, link|
unlink_file orig, link
end
KWM_FILES.each do |orig, link|
unlink_file orig, link
end
KHD_FILES.each do |orig, link|
unlink_file orig, link
end
OTHER_FILES.each do |orig, link|
unlink_file orig, link
end
# # delete unchanged copied files
# COPIED_FILES.each do |orig, copy|
# rm_f copy, :verbose => true if File.read(orig) == File.read(copy)
# end
end
task :default => :install