-
Notifications
You must be signed in to change notification settings - Fork 1
/
Rakefile
36 lines (31 loc) · 1.09 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
require 'rake'
desc "Hook our dotfiles into system-standard positions."
task :install do
linkables = Dir.glob('*/**{.symlink}')
skip_all = false
overwrite_all = false
backup_all = false
linkables.each do |linkable|
overwrite = false
backup = false
file = linkable.split('/').last.sub(/.symlink/,'')
target = "#{ENV["HOME"]}/.#{file}"
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 's' then next
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 "$PWD/#{linkable}" "#{target}"`
end
end
task :default => 'install'