forked from chauncey-garrett/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
430 lines (367 loc) · 11.6 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
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
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
require 'rake'
require 'fileutils'
task :default => 'install:default'
#
# Install scripts...
#
namespace :install do
desc "Install node_modules"
task :node_modules do
if want_to_install?('node_modules')
message_installing("node_modules")
install_node_modules
message_installed("node_modules")
end
end
desc "Install dotfiles"
task :dotfiles do
if want_to_install?('dotfiles')
message_installing("dotfiles")
install_dotfiles
message_installed("dotfiles")
end
end
desc "Setup rbenv (for Ubuntu server, otherwise use Homebrew)"
task :rbenv do
if want_to_install?('rbenv')
message_installing("rbenv")
install_rbenv if RUBY_PLATFORM.downcase.include?("linux")
message_installed("rbenv")
end
end
desc "Install Homebrew (OS X Package Manager)"
task :homebrew do
if want_to_install?('Homebrew (OS X Package Manager)')
message_installing("homebrew")
install_homebrew if RUBY_PLATFORM.downcase.include?("darwin")
message_installed("homebrew")
end
end
desc "Install QuickLook Plugins (OS X only)"
task :osx_quicklook_plugins do
if want_to_install?('QuickLook Plugins')
message_installing("QuickLook Plugins")
install_osx_quicklook_plugins if RUBY_PLATFORM.downcase.include?("darwin")
message_installed("QuickLook Plugins")
end
end
desc "Install coding osx_fonts (OS X only)"
task :osx_fonts do
if want_to_install?('Coding fonts for OS X')
message_installing("osx_fonts")
install_osx_fonts if RUBY_PLATFORM.downcase.include?("darwin")
message_installed("osx_fonts")
end
end
desc "Install saved searches (OS X only)"
task :osx_saved_searches do
if want_to_install?('OS X Saved Searches')
message_installing("OS X Saved Searches")
install_osx_saved_searches if RUBY_PLATFORM.downcase.include?("darwin")
message_installed("OS X Saved Searches")
end
end
desc "Install keybindings (OS X only)"
task :osx_keybindings do
if want_to_install?('Keybindings for OS X')
message_installing("OS X Keybindings")
install_osx_keybindings if RUBY_PLATFORM.downcase.include?("darwin")
message_installed("OS X Keybindings")
end
end
desc "Install Services (OS X only)"
task :osx_services do
if want_to_install?('Services for OS X')
message_installing("Services")
install_osx_services if RUBY_PLATFORM.downcase.include?("darwin")
message_installed("Services")
end
end
desc "Install LaunchAgents (OS X only)"
task :osx_launch_agents do
if want_to_install?('LaunchAgents for OS X')
message_installing("LaunchAgents")
install_osx_launch_agents if RUBY_PLATFORM.downcase.include?("darwin")
message_installed("LaunchAgents")
end
end
desc "Install iTerm2 solarized theme (OS X only)"
task :term_theme do
if want_to_install?('iTerm2 solarized theme for OS X')
message_installing("iTerm2 solarized theme")
install_iterm2_theme_solarized if RUBY_PLATFORM.downcase.include?("darwin")
message_installed("iTerm2 solarized theme")
end
end
desc "Install tern (Vim plugin)"
task :vim_tern do
if want_to_install?('tern (Vim plugin)')
message_installing("tern")
install_tern
message_installed("tern")
end
end
desc "Install Janus (Vim distribution)"
task :janus do
if want_to_install?('Janus (Vim distribution)')
message_installing("janus")
install_janus
message_installed("janus")
end
end
desc "Install default configuration! (dotfiles, Homebrew, Janus, fonts, iTerm2 solarized theme)"
task :default => [ :dotfiles,
:homebrew,
:janus,
:osx_fonts,
:term_theme ] do
message_installed("defaults")
end
desc "Install everything!"
task :all => [ :dotfiles,
:homebrew,
:janus,
:osx_fonts,
:osx_launch_agents,
:osx_services,
:osx_keybindings,
:osx_saved_searches,
:osx_quicklook_plugins,
:term_theme ] do
message_installed("everything")
end
# message_final("successful")
end
#
# Update scripts...
#
namespace :update do
desc "Update dotfiles"
task :dotfiles do
if want_to_install?('dotfiles')
message_updating("dotfiles")
update_dotfiles
message_updated("dotfiles")
end
end
desc "Update Homebrew package manager"
task :homebrew do
if want_to_install?('homebrew')
message_updating("homebrew")
update_homebrew
message_updated("homebrew")
end
end
desc "Update all installed!"
task :all => [ :dotfiles,
:homebrew,
:janus,
:osx_fonts,
:term_theme ] do
message_updated("all")
end
# message_final("successful")
end
#
# Definitions...
#
private
def run(cmd)
puts "[Running] #{cmd}"
`#{cmd}` unless ENV['DEBUG']
end
def want_to_install? (section)
if ENV["ASK"]=="true"
puts "Install: #{section}? [Y]es | [n]o"
STDIN.gets.chomp == 'Y'
else
true
end
end
def install_osx_fonts
run %{ $HOME/.dotfiles/fonts/link-fonts.zsh }
run %{ cp -f $HOME/.dotfiles/fonts/{*.otf,*.ttf} $HOME/Library/Fonts/ }
run %{ chmod 644 $HOME/Library/Fonts/* }
end
def install_osx_quicklook_plugins
run %{ cp -RL -f $HOME/.dotfiles/osx-quicklook-plugins/*qlgenerator $HOME/Library/QuickLook/ }
run %{ cp -f $HOME/.dotfiles/osx-quicklook-plugins/*css $HOME }
run %{ qlmanage -r }
end
def install_osx_keybindings
run %{ mkdir -p $HOME/Library/KeyBindings }
run %{ cp -f $HOME/.dotfiles/keybindings/DefaultKeyBinding.dict $HOME/Library/KeyBindings/ }
run %{ defaults write -g NSRepeatCountBinding -string "^u" }
end
def install_osx_saved_searches
run %{ mkdir -p "$HOME/Library/Saved Searches" }
run %{ cp -f $HOME/.dotfiles/osx-saved-searches/* "$HOME/Library/Saved Searches" }
end
def install_osx_services
run %{ mkdir -p $HOME/Library/Services }
run %{ cp -R -f $HOME/.dotfiles/osx-services/* $HOME/Library/Services/ }
end
def install_osx_launch_agents
run %{ mkdir -p $HOME/Library/LaunchAgents }
run %{ cp -f $HOME/.dotfiles/osx-launch-agents/* $HOME/Library/LaunchAgents/ }
end
def install_iterm2_theme_solarized
run %{ /usr/libexec/PlistBuddy -c "Add :'Custom Color Presets':'Solarized Light' dict" ~/Library/Preferences/com.googlecode.iterm2.plist }
run %{ /usr/libexec/PlistBuddy -c "Merge 'iTerm2/Solarized Light.itermcolors' :'Custom Color Presets':'Solarized Light'" ~/Library/Preferences/com.googlecode.iterm2.plist }
run %{ /usr/libexec/PlistBuddy -c "Add :'Custom Color Presets':'Solarized Dark' dict" ~/Library/Preferences/com.googlecode.iterm2.plist }
run %{ /usr/libexec/PlistBuddy -c "Merge 'iTerm2/Solarized Dark.itermcolors' :'Custom Color Presets':'Solarized Dark'" ~/Library/Preferences/com.googlecode.iterm2.plist }
# If iTerm2 is not installed or has never run, we can't autoinstall the profile since the plist is not there
if !File.exists?(File.join(ENV['HOME'], '/Library/Preferences/com.googlecode.iterm2.plist'))
puts
puts "To ensure your profile is using the solarized theme, please check your settings under:"
puts " Preferences > Profiles > [your profile] > Colors > Load Preset..."
puts "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "
return
end
# Ask the user which theme he wants to install
message = "Which theme would you like to apply to your iTerm2 profile?"
color_scheme = ask message, iTerm_available_themes
color_scheme_file = File.join('iTerm2', "#{color_scheme}.itermcolors")
# Ask the user on which profile he wants to install the theme
profiles = iTerm_profile_list
message = "I've found #{profiles.size} #{profiles.size>1 ? 'profiles': 'profile'} on your iTerm2 configuration, which one would you like to apply the Solarized theme to?"
profiles << 'All'
selected = ask message, profiles
if selected == 'All'
(profiles.size-1).times { |idx| apply_theme_to_iterm_profile_idx idx, color_scheme_file }
else
apply_theme_to_iterm_profile_idx profiles.index(selected), color_scheme_file
end
end
def iTerm_available_themes
Dir['iTerm2/*.itermcolors'].map { |value| File.basename(value, '.itermcolors')}
end
def iTerm_profile_list
profiles=Array.new
begin
profiles << %x{ /usr/libexec/PlistBuddy -c "Print :'New Bookmarks':#{profiles.size}:Name" ~/Library/Preferences/com.googlecode.iterm2.plist 2>/dev/null}
end while $?.exitstatus==0
profiles.pop
profiles
end
def apply_theme_to_iterm_profile_idx(index, color_scheme_path)
values = Array.new
16.times { |i| values << "Ansi #{i} Color" }
values << ['Background Color', 'Bold Color', 'Cursor Color', 'Cursor Text Color', 'Foreground Color', 'Selected Text Color', 'Selection Color']
values.flatten.each { |entry| run %{ /usr/libexec/PlistBuddy -c "Delete :'New Bookmarks':#{index}:'#{entry}'" ~/Library/Preferences/com.googlecode.iterm2.plist } }
run %{ /usr/libexec/PlistBuddy -c "Merge '#{color_scheme_path}' :'New Bookmarks':#{index}" ~/Library/Preferences/com.googlecode.iterm2.plist }
end
def ask(message, values)
puts message
while true
values.each_with_index { |val, idx| puts " #{idx+1}. #{val}" }
selection = STDIN.gets.chomp
if (Float(selection)==nil rescue true) || selection.to_i < 0 || selection.to_i > values.size+1
puts "ERROR: Invalid selection."
puts
puts
else
break
end
end
selection = selection.to_i-1
values[selection]
end
def install_rbenv
run %{ which ruby }
unless $?.success?
run %{ sudo apt-get install ruby }
end
run %{ which git }
unless $?.success?
run %{ sudo apt-get install git }
end
run %{ which rbenv }
unless $?.success?
run %{ sudo apt-get install rbenv }
run %{ gem install bundler }
run %{ git clone -- https://github.com/tpope/rbenv-aliases.git ~/.rbenv/plugins/rbenv-aliases }
run %{ git clone -- https://github.com/ianheggie/rbenv-binstubs.git ~/.rbenv/plugins/rbenv-binstubs }
run %{ git clone -- https://github.com/carsomyr/rbenv-bundler.git ~/.rbenv/plugins/bundler }
run %{ git clone -- https://github.com/tpope/rbenv-ctags.git ~/.rbenv/plugins/rbenv-ctags }
run %{ git clone -- https://github.com/sstephenson/rbenv-gem-rehash.git ~/.rbenv/plugins/rbenv-gem-rehash }
end
end
def install_homebrew
run %{ which brew }
unless $?.success?
run %{ ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)" }
end
run %{ sh Brewfile.sh }
end
def update_homebrew
run %{ which brew }
unless $?.success?
install_homebrew
end
run %{ brew prune }
run %{ brew cleanup }
run %{ brew update }
run %{ brew tap --repair }
run %{ brew doctor }
run %{ brew outdated }
end
def install_tern
run %{ cd "$HOME/.dotfiles/janus/tern" && npm install }
end
def install_janus
puts "Janus requires Vim >= 7.3, ack, ctags, git, ruby and rake."
run %{ curl -Lo- https://bit.ly/janus-bootstrap | bash }
end
def install_node_modules
run %{ yarn }
end
def install_dotfiles
run %{ $HOME/.dotfiles/bin/dotsync -L }
end
def make_zsh_default_shell
if ENV["SHELL"].include? 'zsh' then
# if ENV["SHELL"] =~ /zsh/
puts "Already using Zsh..."
else
print "Make Zsh default? (recommended) [Ynq]"
puts
case $stdin.gets.chomp
when 'Y'
puts "Switching to Zsh..."
run %{ chsh -s /bin/zsh }
when 'q'
puts "Exiting..."
exit
else
puts "Zsh will NOT be the default shell..."
end
end
end
def message_installing(action)
puts
puts "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "
puts "Installing #{action}..."
puts
end
def message_installed(action)
puts
puts "Installed #{action}."
puts "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "
puts
end
def message_updating(action)
puts
puts "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "
puts "Updating #{action}..."
puts
end
def message_updated(action)
puts
puts "Updated #{action}."
puts "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "
puts
end
def message_final(action)
puts "Your configuration was #{action}. Restart your terminal for cake."
end