require 'rake' require 'pathname' task :default => [:link] # you can set template. # # $ rake link FROM=yoshimi_default TO=default # desc "link from template/ENV['FROM'] to ~/.cutagem/templates/ENV['TO']" task :link do |t| from = ENV["FROM"] or raise 'USAGE: $ rake link FROM=walf443_default TO=default' to = ENV['TO'] || 'default' abs_dir_path = (Pathname(File.dirname(__FILE__)) + 'templates' + from).expand_path raise "there is no directory #{abs_dir_path}" unless abs_dir_path.exist? user_template_dir = Pathname(ENV['HOME'] + '/.cutagem/templates/').expand_path if user_template_dir.exist? if ( user_template_dir + to ).exist? print "#{user_template_dir + to} is already exist. force link? [Yn] " answer = $stdin.gets.chomp if answer == 'n' raise "#{user_template_dir + to} is already exist." end end else user_template_dir.mkpath end sh "ln -sf #{abs_dir_path} #{user_template_dir + to}" end