Skip to content
Newer
Older
100644 57 lines (45 sloc) 1.55 KB
9d1f3bf @BRMatt Adding initial files
authored Mar 3, 2012
1 require 'rake'
2
3 desc "Hook our dotfiles into system-standard positions."
4 task :install do
5 linkables = Dir.glob('*/**{.symlink}')
6
7 skip_all = false
8 overwrite_all = false
9 backup_all = false
10
11 linkables.each do |linkable|
12 overwrite = false
13 backup = false
14
15 file = linkable.split('/').last.split('.symlink').last
16 target = "#{ENV["HOME"]}/.#{file}"
17
18 if File.exists?(target) || File.symlink?(target)
19 unless skip_all || overwrite_all || backup_all
20 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"
21 case STDIN.gets.chomp
22 when 'o' then overwrite = true
23 when 'b' then backup = true
24 when 'O' then overwrite_all = true
25 when 'B' then backup_all = true
26 when 'S' then skip_all = true
27 when 's' then next
28 end
29 end
30 FileUtils.rm_rf(target) if overwrite || overwrite_all
31 `mv "$HOME/.#{file}" "$HOME/.#{file}.backup"` if backup || backup_all
32 end
33 `ln -s "$PWD/#{linkable}" "#{target}"`
34 end
35 end
36
37 task :uninstall do
38
39 Dir.glob('**/*.symlink').each do |linkable|
40
41 file = linkable.split('/').last.split('.symlink').last
42 target = "#{ENV["HOME"]}/.#{file}"
43
44 # Remove all symlinks created during installation
45 if File.symlink?(target)
46 FileUtils.rm(target)
47 end
48
49 # Replace any backups made during installation
50 if File.exists?("#{ENV["HOME"]}/.#{file}.backup")
51 `mv "$HOME/.#{file}.backup" "$HOME/.#{file}"`
52 end
53
54 end
55 end
56
57 task :default => 'install'
Something went wrong with that request. Please try again.