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
|
# File 'lib/dottor.rb', line 29
def init
if File.exists?('dottor_rules.yml')
if options[:force]
FileUtils.rm 'dottor_rules.yml'
else
say("Abort: dottor_rules.yml already exist. Use the --force to overwrite.")
exit(1)
end
end
rules_hash = {"profile_name" => []}
exclude_files = ['.gitignore', 'README', 'README.md']
if git_repo?
files_in_current_dir = `git ls-files`.split("\n") - exclude_files
else
files_in_current_dir = Dir["*"] - exclude_files
end
if files_in_current_dir.empty?
rules_hash["profile_name"] = [{"source" => ".dotfile", "target" => "target_path/.dotfile"}]
else
files_in_current_dir.each do |file_name|
rules_hash["profile_name"] << {"source" => file_name, "target" => "target_path/#{file_name}"}
end
end
File.open('dottor_rules.yml', 'w') do |file|
file.write(YAML.dump(rules_hash))
end
say("dottor_rules.yml file created. Modify it and run 'dottor symlink <profile_name>'")
end
|