forked from square/maximum-awesome
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
166 lines (146 loc) · 4.62 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
def brew_install(package, *options)
`brew list #{package}`
return if $?.success?
sh "brew 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 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)
# Symlink already configured properly. Leave it alone.
return if File.symlink?(symlink_path) and File.readlink(symlink_path) == original_path
# Never move user's files without creating backups first
number = 1
loop do
backup_path = "#{symlink_path}.bak"
if number > 1
backup_path = "#{backup_path}#{number}"
end
if File.exists?(backup_path)
number += 1
next
end
mv symlink_path, backup_path, :verbose => true
break
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 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'
system <<-SHELL
curl -L -o iterm.zip http://iterm2.googlecode.com/files/iTerm2-1_0_0_20120203.zip && \
unzip iterm.zip && \
mv iTerm.app /Applications && \
rm iterm.zip
SHELL
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'
system <<-SHELL
curl -L -o macvim.tbz https://github.com/downloads/b4winckler/macvim/MacVim-snapshot-64.tbz && \
bunzip2 macvim.tbz && tar xf macvim.tar && \
mv MacVim-snapshot-64/MacVim.app /Applications && \
rm -rf macvim.tbz macvim.tar MacVim-snapshot-64
SHELL
system ''
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
end
desc 'Install these config files.'
task :default do
Rake::Task['install:brew'].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
step 'git submodules'
sh 'git submodule update --init'
# TODO install gem ctags?
# TODO run gem ctags?
step 'symlink'
link_file 'vim' , '~/.vim'
link_file 'tmux.conf' , '~/.tmux.conf'
link_file 'vimrc' , '~/.vimrc'
unless File.exist?(File.expand_path('~/.vimrc.local'))
cp File.expand_path('vimrc.local'), File.expand_path('~/.vimrc.local'), :verbose => true
end
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