Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Branch: master
Fetching contributors…

Cannot retrieve contributors at this time

58 lines (53 sloc) 1.485 kB
require 'rake'
require 'erb'
desc "install the dot files into user's home directory"
task :install do
replace_all = false
Dir['*'].each do |file|
next if %w[Rakefile README.rdoc LICENSE].include? file
if File.exist?(File.join(ENV['HOME'], ".#{file.sub('.erb', '')}"))
if File.identical? file, File.join(ENV['HOME'], ".#{file.sub('.erb', '')}")
puts "identical ~/.#{file.sub('.erb', '')}"
elsif replace_all
replace_file(file)
else
print "overwrite ~/.#{file.sub('.erb', '')}? [ynaq] "
case $stdin.gets.chomp
when 'a'
replace_all = true
replace_file(file)
when 'y'
replace_file(file)
when 'q'
exit
else
puts "skipping ~/.#{file.sub('.erb', '')}"
end
end
else
link_file(file)
end
end
end
def replace_file(file)
if file =~ /bin/
system %Q{rm -rf "$HOME/#{file}"}
else
system %Q{rm -rf "$HOME/.#{file.sub('.erb', '')}"}
end
link_file(file)
end
def link_file(file)
if file =~ /.erb$/
puts "generating ~/.#{file.sub('.erb', '')}"
File.open(File.join(ENV['HOME'], ".#{file.sub('.erb', '')}"), 'w') do |new_file|
new_file.write ERB.new(File.read(file)).result(binding)
end
elsif file =~ /bin/
puts "linking ~/#{file}"
system %Q{ln -s "$PWD/#{file}" "$HOME/#{file}"}
else
puts "linking ~/.#{file}"
system %Q{ln -s "$PWD/#{file}" "$HOME/.#{file}"}
end
end
Jump to Line
Something went wrong with that request. Please try again.