-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
73 lines (50 loc) · 1.81 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
require 'colorize'
# Directory of the dotfiles repo
DOTFILESDIR = File.dirname __FILE__
# files will be linked to user's home dir.
DESTDIR = ENV['HOME']
task :default => 'dotfiles:make_symlinks'
task :install => 'dotfiles:install'
namespace :dotfiles do
###
# Installs the dotfiles into the destination directory.
task :install do
puts "Pulling dependencies...".colorize(:white)
system "git -C #{DOTFILESDIR} submodule init"
system "git -C #{DOTFILESDIR} submodule update"
Rake::Task["dotfiles:make_symlinks"].invoke
end
###
# Creates symlinks for all files in ~/.dotfiles
task :make_symlinks do
puts "Making symlinks for dotfiles...".colorize(:white)
# list of files to symlink
files = Dir.glob "#{DOTFILESDIR}/**/*.symlink"
files.each do |filepath|
# extract just the filename from the path
filename = File.basename(filepath, File.extname(filepath))
# create the symlinks, overriding any existing links/files.
dest = "#{DESTDIR}/.#{filename}"
# create the symlink and check result
res = system "ln -snFf #{filepath} #{dest}"
puts "ERROR (#{$?.exitstatus})".colorize(:red) unless res
# output
puts "#{filepath} -> #{dest}".colorize(:green)
end
end
task :rm_symlinks do
puts "Removing symlinks for dotfiles...".colorize(:white)
# list of files to symlink
files = Dir.glob "#{DOTFILESDIR}/**/*.symlink"
files.each do |filepath|
# extract just the filename from the path
filename = File.basename(filepath, File.extname(filepath))
# create the symlinks, overriding any existing links/files.
dest = "#{DESTDIR}/.#{filename}"
# create the symlink and check result
res = system "rm #{dest}"
# output
puts "Deleted #{dest}".colorize(:green) if res
end
end
end