-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathRakefile
More file actions
57 lines (51 loc) · 1.31 KB
/
Copy pathRakefile
File metadata and controls
57 lines (51 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
require 'rake'
require 'erb'
$replace_all = false
task :default => :install
desc "Install all the dot files into the current user's home directory."
task :install do
Dir['*'].each do |file|
next if %w[Rakefile README.md LICENSE].include? file
process_file file
end
end
def process_file(file)
target_file = File.join ENV['HOME'], ".#{file.sub('.erb', '')}"
if File.exist? target_file
if File.identical? file, target_file
puts "Files #{file} and #{target_file} are identical."
elsif $replace_all
replace_file file, target_file
else
print "Overwrite #{target_file}? [ynaq] "
case $stdin.gets.chomp
when 'a'
$replace_all = true
replace_file file, target_file
when 'y'
replace_file file, target_file
when 'q'
exit
else
puts "Skipping #{target_file}"
end
end
else
create_file file, target_file
end
end
def replace_file(source, target)
system %Q{rm -rf "#{target}"}
create_file source, target
end
def create_file(source, target)
if source =~ /.erb$/
puts "Generating #{target}"
File.open File.join(target), 'w' do |new_file|
new_file.write ERB.new(File.read(source)).result(binding)
end
else
puts "Creating #{target}"
system %Q{cp -r "$PWD/#{source}" "#{target}"}
end
end