-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
81 lines (66 loc) · 1.78 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
require 'rake'
module FancyPutter
COLORS = %w[black red green yellow blue magenta cyan white]
COLORS.each_with_index do |color, i|
define_method(color.to_sym) do |str|
wrapper(i, str)
end
end
private
def wrapper(color_code, str)
"\033[3#{color_code}m#{str}\033[0m"
end
end
module Installer
include FancyPutter
PATH = File.dirname(File.realdirpath(__FILE__))
HOME = Dir.home
def files_in_dir(dir)
Dir.open(dir).entries.reject { |f| f =~ /^\.{1,2}$/ }
end
def install
files = `find #{PATH}/home -type f`.split("\n")
files.each do |file|
target = "#{HOME}/#{convert_dot_path(file)}"
if File.exist?(target)
if File.symlink?(target)
puts green " Already linked: #{target}"
else
puts yellow " Target file already exists: #{target}"
end
if diff = `diff #{file} #{target}` and !diff.empty?
puts red " There was a conflict with: #{target}"
puts diff
end
else
target_path = File.dirname(target)
FileUtils.mkdir_p(target_path) unless File.exist?(target_path)
if FileUtils.symlink(file, target)
puts green " linked #{target}"
else
puts red " Symlinking failed for: #{file} -> #{target}"
end
end
end
end
private
# returns what the relative path target to the home directory
def convert_dot_path(path)
local_path = path.slice("#{PATH}/home/".length..-1)
local_path.gsub!(/dot\-/, '.')
local_path
end
end
desc "Install dot files"
task :install do
include Installer
Installer.install
end
task default: :install
namespace :test do
task :colortest do
include FancyPutter
puts "Oooooh pretty"
COLORS.each { |c| puts send(c.to_sym, c) }
end
end