added Rakefile. it symlinks from the repo to the home directory.

This commit is contained in:
Kyle West 2012-01-25 01:13:33 -05:00
parent e2b68c4a4e
commit a658b815f5

70
Rakefile Normal file
View File

@ -0,0 +1,70 @@
require 'rake'
desc "Hook our dotfiles into system-standard positions."
task :install => :submodules do
# this has all the linkables from this directory.
linkables = []
linkables += Dir.glob('git/*') if want_to_install?('git')
linkables += Dir.glob('irb/*') if want_to_install?('irb/pry')
linkables += Dir.glob('{vim,vimrc}') if want_to_install?('vim')
linkables += Dir.glob('zsh/oh_my_zsh_zshrc') if want_to_install?('zsh')
skip_all = false
overwrite_all = false
backup_all = false
linkables.each do |linkable|
file = linkable.split('/').last
source = "#{ENV["PWD"]}/#{linkable}"
target = "#{ENV["HOME"]}/.#{file}"
puts "--------"
puts "file: #{file}"
puts "source: #{source}"
puts "target: #{target}"
if File.exists?(target) || File.symlink?(target)
unless skip_all || overwrite_all || backup_all
puts "File already exists: #{target}, what do you want to do? [s]kip, [S]kip all, [o]verwrite, [O]verwrite all, [b]ackup, [B]ackup all"
case STDIN.gets.chomp
when 'o' then overwrite = true
when 'b' then backup = true
when 'O' then overwrite_all = true
when 'B' then backup_all = true
when 'S' then skip_all = true
end
end
FileUtils.rm_rf(target) if overwrite || overwrite_all
`mv "$HOME/.#{file}" "$HOME/.#{file}.backup"` if backup || backup_all
end
`ln -s "#{source}" "#{target}"`
end
success_msg("installed")
end
desc "Init and update submodules."
task :submodules do
sh('git submodule update --init')
end
task :default => 'install'
private
def want_to_install? (section)
puts "Would you like to install configuration files for: #{section}? [y]es, [n]o"
STDIN.gets.chomp == 'y'
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