-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRakefile
106 lines (93 loc) · 2.27 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
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
require 'fileutils'
require 'yaml'
Yobj = YAML::load(File.open('.dotfiles.yml'))
def git_stash(&block)
system("git diff-index --exit-code HEAD > /dev/null")
stash = $?.exitcode > 0
if stash
`git stash save --quiet 'dotfiles'`
end
block.call()
if stash
`git --no-pager stash pop`
end
end
def git_master(&block)
git_stash do
system("git checkout master")
block.call()
system("git checkout local")
system("git rebase master")
end
end
def vimdoctags
print_text("*** Updating vim help tags", :color => 6)
system("vim --noplugin -c 'call pathogen#helptags()' -c 'q'")
end
def filter(hash, pattern)
if pattern
pattern = Regexp.new(pattern)
hash.delete_if do |key, value|
not (key =~ pattern)
end
end
hash.each do |key, value|
yield key, value
end
end
def download(url, file)
print_text("*** Downloading #{file}", :color => 6)
system("wget #{url} -O #{file}")
end
def print_text(text, args={})
color = args[:color]
system("tput setaf #{color}") if color
puts(text)
system("tput sgr0") if color
end
task :default do
end
namespace :bundle do
desc "Initialize bundles"
task :init, :pattern do |t, args|
filter(Yobj['Bundles'], args.pattern) do |key, value|
unless File.exist?(key)
print_text("*** Initializing #{key}", :color => 2)
system("git clone #{value} #{key}")
end
end
vimdoctags
end
desc "Update bundles"
task :update, :pattern do |t, args|
filter(Yobj['Bundles'], args.pattern) do |key, value|
if Dir.exist?(key)
print_text("*** Updating #{key}", :color => 2)
system("cd #{key} && git checkout master && git pull")
else
print_text("*** Bundle #{key} not initialized", :color => 1)
end
end
vimdoctags
end
desc "List bundles"
task :list, :pattern do |t, args|
filter(Yobj['Bundles'], args.pattern) do |key, value|
print_text("#{key} => #{value}")
end
end
end
namespace :file do
desc "Update files"
task :update, :pattern do |t, args|
filter(Yobj['Files'], args.pattern) do |key, value|
download(value, key)
end
end
desc "List files"
task :list, :pattern do |t, args|
filter(Yobj['Files'], args.pattern) do |key, value|
print_text("#{key} => #{value}")
end
end
end