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
|
2010-06-25 17:02:29 +10:00
|
|
|
dot_files = File.dirname(__FILE__)
|
2011-11-08 17:23:58 +11:00
|
|
|
files = %w(
|
|
|
|
editors/vim
|
|
|
|
editors/vim/gvimrc
|
|
|
|
editors/vim/vimrc
|
2011-10-24 14:27:18 +11:00
|
|
|
languages/ruby/autotest/autotest
|
|
|
|
languages/ruby/gemrc
|
|
|
|
languages/ruby/irbrc
|
|
|
|
languages/ruby/rdebugrc
|
2011-11-08 17:23:58 +11:00
|
|
|
misc/ackrc
|
|
|
|
misc/ctags
|
|
|
|
misc/inputrc
|
|
|
|
misc/nanorc
|
|
|
|
misc/tmux.conf
|
|
|
|
shells/bash/bash_profile
|
|
|
|
shells/bash/bashrc
|
|
|
|
shells/zsh/zshenv
|
|
|
|
shells/zsh/zshrc
|
|
|
|
vcs/git/gitattributes
|
2011-10-24 14:27:18 +11:00
|
|
|
vcs/git/gitconfig
|
2012-08-17 07:40:42 +10:00
|
|
|
vcs/git/gitconfig.merge
|
|
|
|
vcs/git/gitconfig.pushurls
|
2011-10-24 14:27:18 +11:00
|
|
|
vcs/git/gitignore
|
2011-11-08 17:23:58 +11:00
|
|
|
vcs/git/gitk
|
2011-11-08 17:52:14 +11:00
|
|
|
vcs/git/git_template
|
2011-10-24 14:27:18 +11:00
|
|
|
vcs/hg/hgrc
|
2011-11-08 17:23:58 +11:00
|
|
|
)
|
2010-11-22 14:50:32 +11:00
|
|
|
|
2011-08-15 02:48:14 +10:00
|
|
|
files = Hash[files.zip(Array.new(files.size, "~/."))]
|
2012-07-20 15:19:12 +10:00
|
|
|
files["languages/clojure/lein/profiles.clj"] = "~/.lein/"
|
2012-08-17 07:40:42 +10:00
|
|
|
|
|
|
|
system "cp -n vcs/git/gitconfig.local ~/.gitconfig.local"
|
2011-02-21 15:52:42 +11:00
|
|
|
|
|
|
|
files.each do |file, destination|
|
2010-06-25 17:02:29 +10:00
|
|
|
file_name = file.split(/\//).last
|
|
|
|
source_file = File.join(dot_files, file)
|
2011-08-15 02:48:14 +10:00
|
|
|
destination_file = File.expand_path("#{destination}#{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-11-22 14:53:35 +11:00
|
|
|
|
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-11-22 14:53:35 +11:00
|
|
|
|
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
|