|
Revision 4323, 0.9 kB
(checked in by walf443, 5 years ago)
|
|
dotfiles/cutagem:
- make this category.
- add Rakefile for setup.
- walf443-default import.
|
| Line | |
|---|
| 1 | require 'rake' |
|---|
| 2 | require 'pathname' |
|---|
| 3 | |
|---|
| 4 | task :default => [:link] |
|---|
| 5 | |
|---|
| 6 | # you can set template. |
|---|
| 7 | # |
|---|
| 8 | # $ rake link FROM=yoshimi_default TO=default |
|---|
| 9 | # |
|---|
| 10 | desc "link from template/ENV['FROM'] to ~/.cutagem/templates/ENV['TO']" |
|---|
| 11 | task :link do |t| |
|---|
| 12 | from = ENV["FROM"] or raise 'USAGE: $ rake link FROM=walf443_default TO=default' |
|---|
| 13 | to = ENV['TO'] || 'default' |
|---|
| 14 | abs_dir_path = (Pathname(File.dirname(__FILE__)) + 'templates' + from).expand_path |
|---|
| 15 | raise "there is no directory #{abs_dir_path}" unless abs_dir_path.exist? |
|---|
| 16 | |
|---|
| 17 | user_template_dir = Pathname(ENV['HOME'] + '/.cutagem/templates/').expand_path |
|---|
| 18 | if user_template_dir.exist? |
|---|
| 19 | if ( user_template_dir + to ).exist? |
|---|
| 20 | print "#{user_template_dir + to} is already exist. force link? [Yn] " |
|---|
| 21 | answer = $stdin.gets.chomp |
|---|
| 22 | if answer == 'n' |
|---|
| 23 | raise "#{user_template_dir + to} is already exist." |
|---|
| 24 | end |
|---|
| 25 | end |
|---|
| 26 | else |
|---|
| 27 | user_template_dir.mkpath |
|---|
| 28 | end |
|---|
| 29 | sh "ln -sf #{abs_dir_path} #{user_template_dir + to}" |
|---|
| 30 | end |
|---|