forked from skwp/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
466 lines (394 loc) · 15.1 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
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
require 'rake'
require 'fileutils'
require File.join(File.dirname(__FILE__), 'bin', 'yadr', 'vundle')
require File.join(File.dirname(__FILE__), 'lib', 'osx_tools_installer')
desc "Hook our dotfiles into system-standard positions."
task :install => [:submodule_init, :submodules] do
puts
puts "======================================================"
puts "Welcome to YADR Installation."
puts "======================================================"
puts
if mac_os_x?
install_osx_dev_tools
install_homebrew
install_npm
end
# this has all the runcoms from this directory.
install_files(Dir.glob('git/*')) if want_to_install?('git configs (color, aliases)')
install_files(Dir.glob('irb/*')) if want_to_install?('irb/pry configs (more colorful)')
install_files(Dir.glob('ruby/*')) if want_to_install?('rubygems config (faster/no docs)')
install_files(Dir.glob('ctags/*')) if want_to_install?('ctags config (better js/ruby support)')
if want_to_install?('vim configuration (highly recommended)')
install_files(Dir.glob('{vim,vimrc}'))
Rake::Task["install_vundle"].execute
end
Rake::Task['install_oh_my_zsh'].execute
install_fonts
install_rvm
install_rvm_binstubs
# SDKMan (Java and Friends)
run %{ curl -s "https://get.sdkman.io" | bash }
if mac_os_x?
run "bin/macos"
install_term_theme
end
run_bundle_config
success_msg("installed")
end
task :install_prezto do
if want_to_install?('zsh enhancements & prezto')
install_prezto
end
end
task :install_oh_my_zsh do
if want_to_install?('zsh enhancements & Oh My ZSH')
install_oh_my_zsh
end
end
desc 'Updates the installation'
task :update do
Rake::Task["vundle_migration"].execute if needs_migration_to_vundle?
Rake::Task["install"].execute
#TODO: for now, we do the same as install. But it would be nice
#not to clobber zsh files
end
task :submodule_init do
unless ENV["SKIP_SUBMODULES"]
run %{ git submodule update --init --recursive }
end
end
desc "Init and update submodules."
task :submodules do
unless ENV["SKIP_SUBMODULES"]
puts "======================================================"
puts "Downloading YADR submodules...please wait"
puts "======================================================"
run %{
cd $HOME/.yadr
git submodule update --recursive
git clean -df
}
puts
end
end
desc "Performs migration from pathogen to vundle"
task :vundle_migration do
puts "======================================================"
puts "Migrating from pathogen to vundle vim plugin manager. "
puts "This will move the old .vim/bundle directory to"
puts ".vim/bundle.old and replacing all your vim plugins with"
puts "the standard set of plugins. You will then be able to "
puts "manage your vim's plugin configuration by editing the "
puts "file .vim/vundles.vim"
puts "======================================================"
Dir.glob(File.join('vim', 'bundle','**')) do |sub_path|
run %{git config -f #{File.join('.git', 'config')} --remove-section submodule.#{sub_path}}
# `git rm --cached #{sub_path}`
FileUtils.rm_rf(File.join('.git', 'modules', sub_path))
end
FileUtils.mv(File.join('vim','bundle'), File.join('vim', 'bundle.old'))
end
desc "Runs Vundle installer in a clean vim environment"
task :install_vundle do
puts "======================================================"
puts "Installing and updating vundles."
puts "The installer will now proceed to run PluginInstall to install vundles."
puts "======================================================"
puts ""
vundle_path = File.join('vim','bundle', 'vundle')
unless File.exists?(vundle_path)
run %{
cd $HOME/.yadr
git clone https://github.com/gmarik/vundle.git #{vundle_path}
}
end
Vundle::update_vundle
end
task :default => 'install'
private
def run(cmd)
puts "[Running] #{cmd}"
if ENV['DEBUG']
`echo`
else
system cmd
end
end
def number_of_cores
if RUBY_PLATFORM.downcase.include?("darwin")
run %{ sysctl -n hw.ncpu }
cores = `sysctl -n hw.ncpu`
else
run %{ nproc }
cores = `nproc`
end
puts
cores.to_i
end
def run_bundle_config
return unless system("which bundle")
bundler_jobs = number_of_cores - 1
puts "======================================================"
puts "Configuring Bundlers for parallel gem installation"
puts "======================================================"
run %{ bundle config --global jobs #{bundler_jobs} }
puts
end
def install_rvm
puts "======================================================"
puts "RVM"
puts "======================================================"
if system("rvm --version").nil?
puts "Installing"
run %{ gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 }
run %{ curl -sSL https://get.rvm.io | bash -s stable }
else
ruts "Updating"
run %{ rvm get stable }
end
puts
end
def install_rvm_binstubs
puts "======================================================"
puts "Installing RVM Bundler support. Never have to type"
puts "bundle exec again! Please use bundle --binstubs and RVM"
puts "will automatically use those bins after cd'ing into dir."
puts "======================================================"
run %{ chmod +x $rvm_path/hooks/after_cd_bundler }
puts
end
def install_osx_dev_tools
puts '======================================================'
puts 'Installing OS X development tools/XCode'
puts '======================================================'
OSXToolsInstaller.new.install!
puts
puts
end
def install_homebrew
run %{which brew}
unless $?.success?
puts "======================================================"
puts "Installing Homebrew, the OSX package manager...If it's"
puts "already installed, this will do nothing."
puts "======================================================"
run %{bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"}
end
brews_installed_list = `brew list`.split.grep(/\w+/)
brewz = {
:original => %w{
zsh ctags git hub tmux reattach-to-user-namespace the_silver_searcher ghi
gnupg wget youtube-dl watch
htop imagemagick node tree graphviz
openjdk bat jq
},
:cask => %w{
firefox google-chrome spotify vlc
macvim ngrok iterm2 fork atom visualvm intellij-idea-ce sequel-ace
the-unarchiver keepassxc evernote
quicklook-json quicklook-csv
zsa-wally zoom docker
monitorcontrol istat-menus intel-power-gadget
kensington-trackball-works syncthing
}
}
puts
puts
puts "======================================================"
puts "Updating Homebrew."
puts "======================================================"
run %{brew update}
puts
puts
brews_updates_list = `brew outdated`.split("\n").
collect { |line| line.split.map(&:strip).first }
casks_installed_list = `brew list --cask`.split.grep(/\w+/)
brew_install_list = brewz[:original].reject { |c| brews_installed_list.include? c }
cask_install_list = brewz[:cask].reject { |c| casks_installed_list.include? c }
puts "======================================================"
puts "Installing & Updating Homebrew packages..."
puts "There may be some warnings."
puts "======================================================"
brew_install_list.each do |formula|
run %{brew install #{formula}}
end
cask_env = 'HOMEBREW_CASK_OPTS="--appdir=/Applications"'
cask_install_list.each do |formula|
run %{#{cask_env} brew install --cask #{formula}}
end
run %{brew upgrade #{brews_updates_list.join(' ')}} unless brews_updates_list.empty?
puts
puts
puts "====================================================="
puts "Some tricks..."
puts "====================================================="
run %{sudo chown root:wheel `which htop`}
run %{sudo chmod u+s `which htop`}
run %{defaults write com.apple.finder QLEnableTextSelection -bool true && killall Finder}
puts
puts
end
def install_npm
puts "======================================================"
puts "Installing usefull NPM modules."
puts "======================================================"
end
def install_fonts
puts "======================================================"
puts "Installing patched fonts for Powerline/Lightline."
puts "======================================================"
run %{ cp -f $HOME/.yadr/fonts/* $HOME/Library/Fonts } if RUBY_PLATFORM.downcase.include?("darwin")
run %{ mkdir -p ~/.fonts && cp ~/.yadr/fonts/* ~/.fonts && fc-cache -vf ~/.fonts } if RUBY_PLATFORM.downcase.include?("linux")
puts
end
def install_term_theme
puts "======================================================"
puts "Installing iTerm2 solarized theme."
puts "======================================================"
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 make sure your profile is using the solarized theme"
puts "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
return if color_scheme == 'None'
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')} << 'None'
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 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.\n\n"
else
break
end
end
selection = selection.to_i-1
values[selection]
end
def mac_os_x?
RUBY_PLATFORM.downcase.include?("darwin")
end
def install_oh_my_zsh
puts "======================================================"
puts "Installing Oh My ZSH (ZSH Enhancements)..."
puts "======================================================"
run %{ ln -nfs "$HOME/.yadr/zsh/oh_my_zsh/overwrites/zshrc" "$HOME/.zshrc" }
puts
setup_zsh
install_iterm_integration if mac_os_x?
puts
puts
end
def setup_zsh
if "#{ENV['SHELL']}".include? 'zsh' then
puts "Zsh is already configured as your shell of choice. Restart your session to load the new settings"
else
puts "Setting zsh as your default shell"
if File.exists?("/usr/local/bin/zsh")
if File.readlines("/private/etc/shells").grep("/usr/local/bin/zsh").empty?
puts "Adding zsh to standard shell list"
run %{ echo "/usr/local/bin/zsh" | sudo tee -a /private/etc/shells }
end
run %{ chsh -s /usr/local/bin/zsh }
else
run %{ chsh -s /bin/zsh }
end
end
end
def install_iterm_integration
puts "======================================================"
puts "Installing iTerm2 shell integration."
puts "======================================================"
run %{ curl -L https://iterm2.com/misc/zsh_startup.in > $HOME/.yadr/zsh/iterm2_shell_integration.zsh }
run %{ echo "source $HOME/.yadr/zsh/iterm2_shell_integration.zsh" >> "$HOME/.zshrc" } unless File.read("#{ENV['HOME']}/.zshrc").include?("iterm2_shell_integration")
end
def want_to_install? (section)
if ENV["ASK"]=="true"
puts "Would you like to install configuration files for: #{section}? [y]es, [n]o"
STDIN.gets.chomp == 'y'
else
true
end
end
def install_files(files, method = :symlink)
files.each do |f|
file = f.split('/').last
source = "#{ENV["PWD"]}/#{f}"
target = "#{ENV["HOME"]}/.#{file}"
puts "======================#{file}=============================="
puts "Source: #{source}"
puts "Target: #{target}"
if File.exists?(target) && (!File.symlink?(target) || (File.symlink?(target) && File.readlink(target) != source))
puts "[Overwriting] #{target}...leaving original at #{target}.backup..."
run %{ mv "$HOME/.#{file}" "$HOME/.#{file}.backup" }
end
if method == :symlink
run %{ ln -nfs "#{source}" "#{target}" }
else
run %{ cp -f "#{source}" "#{target}" }
end
puts "=========================================================="
puts
end
end
def needs_migration_to_vundle?
File.exists? File.join('vim', 'bundle', 'tpope-vim-pathogen')
end
def list_vim_submodules
result=`git submodule -q foreach 'echo $name"||"\`git remote -v | awk "END{print \\\\\$2}"\`'`.select{ |line| line =~ /^vim.bundle/ }.map{ |line| line.split('||') }
Hash[*result.flatten]
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 }
run %{ defaults read com.googlecode.iterm2 }
end
def success_msg(action)
puts %q{
_ _ _
| | | | | |
| |___| |_____ __| | ____
|_____ (____ |/ _ |/ ___)
_____| / ___ ( (_| | |
(_______\_____|\____|_|
}
puts "YADR has been #{action}. Please restart your terminal and vim."
end