2008-08-26 08:43:57 +10:00
|
|
|
require 'rake'
|
|
|
|
|
|
|
|
desc "install the dot files into user's home directory"
|
|
|
|
task :install do
|
|
|
|
replace_all = false
|
2010-06-25 17:02:29 +10:00
|
|
|
dot_files = File.dirname(__FILE__)
|
|
|
|
files = %w(zsh/zshrc
|
|
|
|
bash/bashrc
|
|
|
|
bash/bash_profile
|
|
|
|
misc/ackrc
|
|
|
|
misc/inputrc
|
|
|
|
misc/nanorc
|
|
|
|
ruby/autotest/autotest
|
|
|
|
ruby/gemrc
|
|
|
|
ruby/irbrc
|
|
|
|
ruby/rdebugrc
|
2010-06-27 23:34:16 +10:00
|
|
|
git/gitk
|
2010-06-25 17:02:29 +10:00
|
|
|
git/gitconfig
|
|
|
|
git/gitignore
|
2010-11-22 14:50:32 +11:00
|
|
|
git/gitattributes
|
|
|
|
vim/gvimrc.local
|
|
|
|
vim/vimrc.local)
|
|
|
|
|
|
|
|
files.each do |file|
|
2010-06-25 17:02:29 +10:00
|
|
|
file_name = file.split(/\//).last
|
|
|
|
source_file = File.join(dot_files, file)
|
|
|
|
destination_file = File.join(ENV['HOME'], ".#{file_name}")
|
2010-11-22 14:50:32 +11:00
|
|
|
|
2010-06-25 17:02:29 +10:00
|
|
|
if File.exist?(destination_file) || File.symlink?(destination_file)
|
2008-08-26 08:43:57 +10:00
|
|
|
if replace_all
|
2010-06-25 17:02:29 +10:00
|
|
|
replace_file(destination_file, source_file)
|
2008-08-26 08:43:57 +10:00
|
|
|
else
|
2010-06-25 17:02:29 +10:00
|
|
|
print "overwrite #{destination_file}? [ynaq] "
|
|
|
|
case $stdin.gets.chomp.downcase
|
2008-08-26 08:43:57 +10:00
|
|
|
when 'a'
|
|
|
|
replace_all = true
|
2010-06-25 17:02:29 +10:00
|
|
|
replace_file(destination_file, source_file)
|
2008-08-26 08:43:57 +10:00
|
|
|
when 'y'
|
2010-06-25 17:02:29 +10:00
|
|
|
replace_file(destination_file, source_file)
|
2008-08-26 08:43:57 +10:00
|
|
|
when 'q'
|
|
|
|
exit
|
|
|
|
else
|
2010-06-25 17:02:29 +10:00
|
|
|
puts "skipping #{destination_file}"
|
2008-08-26 08:43:57 +10:00
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
2010-06-25 17:02:29 +10:00
|
|
|
link_file(destination_file, source_file)
|
2008-08-26 08:43:57 +10:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-06-25 17:02:29 +10:00
|
|
|
def replace_file(old_file, new_file)
|
|
|
|
system %Q{rm "#{old_file}"}
|
|
|
|
link_file(old_file, new_file)
|
2008-08-26 08:43:57 +10:00
|
|
|
end
|
|
|
|
|
2010-06-25 17:02:29 +10:00
|
|
|
def link_file(old_file, new_file)
|
|
|
|
puts "#{old_file} => #{new_file}"
|
|
|
|
system %Q{ln -fs "#{new_file}" "#{old_file}"}
|
|
|
|
end
|