forked from t6d/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRakefile
More file actions
81 lines (62 loc) · 1.29 KB
/
Rakefile
File metadata and controls
81 lines (62 loc) · 1.29 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
require 'fileutils'
module GitHelper
def git(*args)
if not `which git`.strip.empty?
command = "git #{args.join(' ')}"
puts command
system command
else
raise "Git is not installed"
end
end
end
module FileHelper
include FileUtils
def backup(file)
if File.exists?(file) and not File.symlink?(file)
cp_r file, "#{file}.#{today}"
end
end
def delete(file)
if File.symlink?(file)
rm file
elsif File.exists?(file)
if File.directory?(file)
rm_r file
else
rm file
end
end
end
def link(source, destination)
ln_s source, destination
end
def ignore?(file)
case File.basename(file)
when "Rakefile" then true
else
false
end
end
private
def today
Time.now.strftime("%Y%m%d%H%M%S")
end
end
include GitHelper
include FileHelper
# -- Tasks -----------------------------------------------------------------
task :default => :install
desc "Install all dotfiles"
task :install do
Dir.glob(File.join(File.dirname(__FILE__), '*')) do |src|
dst = File.expand_path(File.join('~', ".#{File.basename(src)}"))
next if ignore?(src)
backup(dst)
delete(dst)
link(src, dst)
end
end
task :update do
git 'pull'
end