forked from ryanb/dotfiles
/
Rakefile
85 lines (70 loc) · 2.42 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
require 'rake'
require 'mustache'
require 'highline/import'
require 'yaml'
SKIP_FILES = [
'settings.yml', 'Gemfile', 'Gemfile.lock',
'LICENSE', 'README.md', 'Rakefile', '*.mustache',
'Brewfile', '#*#', 'emacs.d'
]
# set this to true to do a dry run
DRY = ENV['DRY'] || false
def settings
return @settings if @settings
@settings = {}
settings = YAML.load(open('settings.yml'))
settings.each_pair do |key, value|
@settings[key.to_sym] = value
end
@settings
end
desc "sets up the rcrc environment"
task :setup do
dotfile_dir = File.dirname __FILE__
settings_file = File.expand_path 'settings.yml', dotfile_dir
if File.exist? settings_file
puts "Edit the settings file #{settings_file} to edit configuration values"
else
git_full_name = ask "#{HighLine.color("Full name used for git", HighLine::BOLD)}: "
git_email = ask "#{HighLine.color("Email address used for git", HighLine::BOLD)}: "
github_username = ask "#{HighLine.color("GitHub username", HighLine::BOLD)}: "
rcm_excludes = ask "#{HighLine.color("dotfiles/globs to exclude from your home directory separated by spaces (e.x. vim*)", HighLine::BOLD)}: "
debian_full_name = ask "#{HighLine.color("Full name used for debian packaging", HighLine::BOLD)}: "
debian_email = ask "#{HighLine.color("Email address used for debian packaging", HighLine::BOLD)}: "
File.open settings_file, 'w+', 0644 do |f|
f.write <<-EOF
---
git_full_name: #{git_full_name}
git_email: #{git_email}
github_username: #{github_username}
rcm_excludes: #{rcm_excludes}
EOF
# force a re-read of the configuration file
@settings = nil
end
File.open File.join(ENV['HOME'], '.zshenv.local'), 'w+', 0644 do |f|
f.write <<-EOF
DEBEMAIL="#{debian_email}"
DEBFULLNAME="#{debian_full_name}"
export DEBEMAIL DEBFULLNAME
EOF
end
rcrc_file = File.join ENV['HOME'], '.rcrc'
skip_files = SKIP_FILES + (settings[:rcm_excludes].nil? ? [] : settings[:rcm_excludes].split(/\s+/))
File.open rcrc_file, 'w+', 0644 do |f|
f.write <<-EOF
EXCLUDES="#{skip_files.join(' ')}"
DOTFILES_DIRS="#{dotfile_dir}"
EOF
end
Dir.chdir File.dirname(__FILE__) do
Dir['*.mustache'].each do |file|
output_file = file.gsub /\.mustache$/, ''
rendered = Mustache.render(open(file).read, settings)
File.open output_file, 'w+' do |f|
f << rendered
end
end
end
end
end