-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
39 lines (33 loc) · 1008 Bytes
/
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
class DotFiles
def self.install!
files.each do |file_name|
origin_path = File.expand_path(file_name)
destination_path = File.expand_path("~/#{file_name}")
if exists?(destination_path)
puts "- #{destination_path} (exists)"
else
File.symlink(origin_path, destination_path)
puts "- #{destination_path}"
end
end
end
private
def self.files
files = Dir.glob('*',File::FNM_DOTMATCH)
files = files.reject { |file_name| skip_file?(file_name) }
files.reject { |file_name| !exists?(file_name) }
end
def self.exists?(file_name)
File.exists?(file_name) || File.symlink?(file_name)
end
def self.skip_file?(file_name)
extenstion = File.extname(file_name)
ignored_file = %w{README.md Rakefile . .. .git bin}.include?(file_name)
ignored_extension = %{.md .swp}.include?(extenstion) if extenstion != ""
ignored_file || ignored_extension
end
end
desc "install dotfiles"
task :install do
DotFiles.install!
end