forked from square/maximum-awesome
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
203 lines (175 loc) · 5.63 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
ENV['HOMEBREW_CASK_OPTS'] = "--appdir=/Applications"
def brew_install(package, *options)
`brew list #{package}`
return if $?.success?
sh "brew install #{package} #{options.join ' '}"
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 brew_cask_install(package, *options)
output = `brew cask info #{package}`
return unless output.include?('Not installed')
sh "brew cask install #{package} #{options.join ' '}"
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
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.github.com/mxcl/homebrew/go)"')
raise "Homebrew must be installed before continuing."
end
end
desc 'Install Homebrew Cask'
task :brew_cask do
step 'Homebrew Cask'
unless system('brew tap | grep phinze/cask > /dev/null') || system('brew tap phinze/homebrew-cask')
abort "Failed to tap phinze/homebrew-cask in Homebrew."
end
brew_install 'brew-cask'
end
desc 'Install The Silver Searcher'
task :the_silver_searcher do
step 'the_silver_searcher'
brew_install 'the_silver_searcher'
end
desc 'Install iTerm'
task :iterm do
step 'iterm2'
unless app? 'iTerm'
brew_cask_install 'iterm2'
end
end
desc 'Install ctags'
task :ctags do
step 'ctags'
brew_install 'ctags'
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'
end
desc 'Install MacVim'
task :macvim do
step 'MacVim'
unless app? 'MacVim'
brew_cask_install 'macvim'
end
bin_vim = File.expand_path('~/bin/vim')
FileUtils.mkdir_p(File.dirname(bin_vim))
unless File.executable?(bin_vim)
File.open(bin_vim, 'w', 0744) do |io|
io << <<-SHELL
#!/bin/bash
exec /Applications/MacVim.app/Contents/MacOS/Vim "$@"
SHELL
end
end
end
desc 'Install Vundle'
task :vundle do
step 'vundle'
install_github_bundle 'gmarik','vundle'
sh 'vim -c "BundleInstall" -c "q" -c "q"'
end
end
desc 'Install these config files.'
task :default do
Rake::Task['install:brew'].invoke
Rake::Task['install:brew_cask'].invoke
Rake::Task['install:the_silver_searcher'].invoke
Rake::Task['install:iterm'].invoke
Rake::Task['install:ctags'].invoke
Rake::Task['install:reattach_to_user_namespace'].invoke
Rake::Task['install:tmux'].invoke
Rake::Task['install:macvim'].invoke
# TODO install gem ctags?
# TODO run gem ctags?
step 'symlink'
link_file 'vim' , '~/.vim'
link_file 'tmux.conf' , '~/.tmux.conf'
link_file 'vimrc' , '~/.vimrc'
link_file 'vimrc.bundles' , '~/.vimrc.bundles'
unless File.exist?(File.expand_path('~/.vimrc.local'))
cp File.expand_path('vimrc.local'), File.expand_path('~/.vimrc.local'), :verbose => true
end
unless File.exist?(File.expand_path('~/.vimrc.bundles.local'))
cp File.expand_path('vimrc.bundles.local'), File.expand_path('~/.vimrc.bundles.local'), :verbose => true
end
# Install Vundle and bundles
Rake::Task['install:vundle'].invoke
step 'iterm2 colorschemes'
colorschemes = `defaults read com.googlecode.iterm2 'Custom Color Presets'`
dark = colorschemes !~ /Solarized Dark/
light = colorschemes !~ /Solarized Light/
sh('open', '-a', '/Applications/iTerm.app', File.expand_path('iterm2-colors-solarized/Solarized Dark.itermcolors')) if dark
sh('open', '-a', '/Applications/iTerm.app', File.expand_path('iterm2-colors-solarized/Solarized Light.itermcolors')) if light
step 'iterm2 profiles'
puts
puts " Your turn!"
puts
puts " Go and manually set up Solarized Light and Dark profiles in iTerm2."
puts " (You can do this in 'Preferences' -> 'Profiles' by adding a new profile,"
puts " then clicking the 'Colors' tab, 'Load Presets...' and choosing a Solarized option.)"
puts " Also be sure to set Terminal Type to 'xterm-256color' in the 'Terminal' tab."
puts
puts " Enjoy!"
puts
end