From a658b815f57cafd4ee884ee8883ebf72300e5dc8 Mon Sep 17 00:00:00 2001 From: Kyle West Date: Wed, 25 Jan 2012 01:13:33 -0500 Subject: [PATCH] added Rakefile. it symlinks from the repo to the home directory. --- Rakefile | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 Rakefile diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..8445fc5 --- /dev/null +++ b/Rakefile @@ -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