-
Notifications
You must be signed in to change notification settings - Fork 1
/
Rakefile
61 lines (52 loc) · 1.7 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
%w[rubygems rake yaml shellwords].each {|l| require l }
BINDIR = File.expand_path("~/bin")
SOURCEDIR = File.expand_path(File.dirname(__FILE__))
SECRETS = File.expand_path('~/.dotfiles_secrets')
UTILS = Dir["shell/*"] + %w[
audiobook-merge/audiobook-merge.rb
diskmonitor/diskmonitor.rb
~/code/cronic/cronic
~/code/cronify/cronify
].select {|f| File.exist?(File.expand_path(f)) }
def secrets
@secrets ||= begin
path = File.expand_path('~/.dotfiles_secrets')
if File.exist?(path)
YAML.load(open(path))
else
{}
end
end
end
task :default => :install
desc "Install utility scripts to #{BINDIR}
secrets in ~/.dotfiles_secrets like
filename:
'search_term': replace_term
'other_search_term': other_replace_term"
task :install
UTILS.each do |script|
scriptfile_base = File.basename(script, ".*")
scriptfile = File.expand_path(script)
binfile = File.join(BINDIR, scriptfile_base)
task install: scriptfile_base
desc "file #{binfile} => #{script}"
task scriptfile_base => binfile
file binfile => scriptfile do
puts "## #{script}"
mkdir_p BINDIR
rm binfile if File.exist?(binfile) || File.symlink?(binfile)
if secrets[scriptfile_base]
cp scriptfile, binfile
system %Q{chmod u+x "#{binfile}"}
secrets[scriptfile_base].each do |search_term, replace_term|
system %[ruby -pi -e 'gsub(/#{Shellwords.escape(search_term)}/, "#{Shellwords.escape(replace_term)}")' "#{binfile}"]
end
puts "… and secrets replaced in #{script}"
else
ln_s scriptfile, binfile
system %Q{chmod u+x "#{scriptfile}"}
end
puts
end
end