forked from jmhobbs/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
55 lines (47 loc) · 1.35 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
44
45
46
47
48
49
50
51
52
53
54
55
require 'rake'
# snaked from https://raw.github.com/nicknisi/dotfiles/master/Rakefile
# loosely based on zholman's install script
def linkables
linkables = Dir.glob('**/*.symlink')
linkables.each do |linkable|
file = linkable.split('/').last.split('.symlink').last
target = "#{ENV["HOME"]}/.#{file}"
puts file, target
yield linkable, file, target if block_given?
end
end
desc "make a backup of all files that will be replaced (if they exist)"
task :backup do
linkables do |linkable, file, target|
if File.exists?(target) || File.symlink?(target)
`mv "$HOME/.#{file}" "$HOME/.#{file}.backup"`
end
end
end
desc "restore the backups"
task :restore do
linkables do |linkable, file, target|
if File.exists?("#{ENV['HOME']}/.#{file}.backup")
`mv "$HOME/.#{file}.backup" "$HOME/.#{file}"`
end
end
end
desc "create all the symlinks"
task :install do
linkables do |linkable, file, target|
unless File.exists?(target)
`ln -s "$PWD/#{linkable}" "#{target}"`
end
end
`[ -e ~/.vim/bundle/vundle ] || git clone https://github.com/gmarik/vundle.git ~/.vim/bundle/vundle`
`[ -e ~/.vim/backup ] || mkdir -p ~/.vim/backup`
end
desc "remove all files added"
task :uninstall do
linkables do |linkable, file, target|
if File.symlink?(target)
FileUtils.rm(target)
end
end
end
task :default => 'install'