forked from skwp/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
185 lines (154 loc) · 5.82 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
require 'rake'
desc "Hook our dotfiles into system-standard positions."
task :install => [:submodule_init, :submodules] do
puts
puts "======================================================"
puts "Welcome to YADR Installation."
puts "======================================================"
puts
install_homebrew if RUBY_PLATFORM.downcase.include?("darwin")
install_rvm_binstubs
# this has all the runcoms from this directory.
file_operation(Dir.glob('git/*')) if want_to_install?('git configs (color, aliases)')
file_operation(Dir.glob('irb/*')) if want_to_install?('irb/pry configs (more colorful)')
file_operation(Dir.glob('ruby/*')) if want_to_install?('rubygems config (faster/no docs)')
file_operation(Dir.glob('ctags/*')) if want_to_install?('ctags config (better js/ruby support)')
file_operation(Dir.glob('tmux/*')) if want_to_install?('tmux config')
file_operation(Dir.glob('vimify/*')) if want_to_install?('vimification of command line tools')
file_operation(Dir.glob('{vim,vimrc}')) if want_to_install?('vim configuration (highly recommended)')
Rake::Task["install_prezto"].execute
install_fonts if RUBY_PLATFORM.downcase.include?("darwin")
success_msg("installed")
end
task :install_prezto do
if want_to_install?('zsh enhancements & prezto')
install_prezto
end
end
task :update => [:install] do
#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 foreach 'git fetch origin; git checkout master; git reset --hard origin/master; git submodule update --recursive; git clean -dfx'
git clean -dfx
}
puts
end
end
task :default => 'install'
private
def run(cmd)
puts "[Running] #{cmd}"
`#{cmd}` unless ENV['DEBUG']
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_homebrew
puts "======================================================"
puts "Installing Homebrew, the OSX package manager...If it's"
puts "already installed, this will do nothing."
puts "======================================================"
run %{ruby -e "$(curl -fsSkL raw.github.com/mxcl/homebrew/go)"}
puts
puts
puts "======================================================"
puts "Installing Homebrew packages...There may be some warnings."
puts "======================================================"
run %{brew install ack ctags git hub}
puts
puts
end
def install_fonts
puts "======================================================"
puts "Installing patched fonts for Powerline."
puts "======================================================"
run %{ cp -f $HOME/.yadr/fonts/* $HOME/Library/Fonts }
puts
end
def install_prezto
puts
puts "Installing Prezto (ZSH Enhancements)..."
unless File.exists?(File.join(ENV['ZDOTDIR'] || ENV['HOME'], ".zprezto"))
run %{ ln -nfs "$HOME/.yadr/zsh/prezto" "${ZDOTDIR:-$HOME}/.zprezto" }
# The prezto runcoms are only going to be installed if zprezto has never been installed
file_operation(Dir.glob('zsh/prezto/runcoms/z*'), :copy)
end
puts
puts "Overriding prezto ~/.zpreztorc with YADR's zpreztorc to enable additional modules..."
run %{ ln -nfs "$HOME/.yadr/zsh/prezto-override/zpreztorc" "${ZDOTDIR:-$HOME}/.zpreztorc" }
puts
puts "Creating directories for your customizations"
run %{ mkdir -p $HOME/.zsh.before }
run %{ mkdir -p $HOME/.zsh.after }
run %{ mkdir -p $HOME/.zsh.prompts }
puts "Setting zsh as your default shell"
run %{ chsh -s /bin/zsh }
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 file_operation(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)
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
# Temporary solution until we find a way to allow customization
# This modifies zshrc to load all of yadr's zsh extensions.
# Eventually yadr's zsh extensions should be ported to prezto modules.
if file == 'zshrc'
File.open(target, 'a') do |zshrc|
zshrc.puts('for config_file ($HOME/.yadr/zsh/*.zsh) source $config_file')
end
end
puts "=========================================================="
puts
end
end
def success_msg(action)
puts ""
puts " _ _ _ "
puts " | | | | | | "
puts " | |___| |_____ __| | ____ "
puts " |_____ (____ |/ _ |/ ___) "
puts " _____| / ___ ( (_| | | "
puts " (_______\_____|\____|_| "
puts ""
puts "YADR has been #{action}. Please restart your terminal and vim."
end