dotfiles/Rakefile

72 lines
2.0 KiB
Ruby
Raw Normal View History

2008-08-26 08:43:57 +10:00
require 'rake'
2010-11-22 14:53:35 +11:00
2008-08-26 08:43:57 +10:00
desc "install the dot files into user's home directory"
task :install do
replace_all = false
dot_files = File.dirname(__FILE__)
2011-10-24 14:14:51 +11:00
files = %w(shells/zsh/zshrc
shells/zsh/zshenv
shells/bash/bashrc
shells/bash/bash_profile
misc/ackrc
misc/inputrc
misc/nanorc
2011-08-15 03:07:06 +10:00
misc/ctags
ruby/autotest/autotest
ruby/gemrc
ruby/irbrc
ruby/rdebugrc
git/gitk
git/gitconfig
git/gitignore
2010-11-22 14:50:32 +11:00
git/gitattributes
2011-03-26 18:34:17 +11:00
hg/hgrc
vim
vim/gvimrc
vim/vimrc)
2010-11-22 14:50:32 +11:00
files = Hash[files.zip(Array.new(files.size, "~/."))]
2011-02-21 15:52:42 +11:00
files["ruby/global.gems"] = "~/.rvm/gemsets/"
files.each do |file, destination|
file_name = file.split(/\//).last
source_file = File.join(dot_files, file)
destination_file = File.expand_path("#{destination}#{file_name}")
2010-11-22 14:50:32 +11:00
if File.exist?(destination_file) || File.symlink?(destination_file)
2008-08-26 08:43:57 +10:00
if replace_all
replace_file(destination_file, source_file)
2008-08-26 08:43:57 +10:00
else
print "overwrite #{destination_file}? [ynaq] "
case $stdin.gets.chomp.downcase
2008-08-26 08:43:57 +10:00
when 'a'
replace_all = true
replace_file(destination_file, source_file)
2008-08-26 08:43:57 +10:00
when 'y'
replace_file(destination_file, source_file)
2008-08-26 08:43:57 +10:00
when 'q'
exit
else
puts "skipping #{destination_file}"
2008-08-26 08:43:57 +10:00
end
end
else
link_file(destination_file, source_file)
2008-08-26 08:43:57 +10:00
end
end
2011-10-24 14:14:51 +11:00
File.open(File.expand_path("~/.dot-files"), 'w') do |f|
f.print "export DOT_FILES=#{File.dirname(__FILE__).inspect}"
end
2008-08-26 08:43:57 +10:00
end
2010-11-22 14:53:35 +11: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-11-22 14:53:35 +11:00
def link_file(old_file, new_file)
puts "#{old_file} => #{new_file}"
system %Q{ln -fs "#{new_file}" "#{old_file}"}
end