-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
43 lines (40 loc) · 1.07 KB
/
Rakefile
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
require 'erb'
require 'rake'
desc 'install dotfiles into home directory'
task :default do
replace_all = false
Dir['_*'].each do |src|
$stderr.write("\n")
dst = File.join(ENV['HOME'], src.sub(/^_(.*?)(\.erb)?$/, '.\\1'))
if File.exist?(dst)
if File.identical?(src, dst)
$stderr.write("Skipping identical '#{dst}'\n")
next
elsif not replace_all
$stderr.write("Are you sure you want to overwrite '#{dst}' [ynaq]? ")
case $stdin.gets.chomp
when 'y'
# Replace file
when 'a'
replace_all = true
when 'q'
exit
else
$stderr.write("Skipping '#{dst}'\n")
next
end
end
rm_r(dst, verbose: false)
end
# Install src to dst
if src =~ /\.erb/
$stderr.write("Generating '#{dst}' from '#{src}'\n")
File.open(dst, 'w') do |file|
file.write(ERB.new(File.read(src)).result)
end
else
$stderr.write("Linking '#{dst}' to '#{src}'\n")
ln_s(File.expand_path(src), dst, verbose: false)
end
end
end