-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathRakefile
46 lines (36 loc) · 1.24 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
require "rake"
require "fileutils"
# The directory for dotfiles that should be symlinked
DOTFILES_DIRECTORY = "tilde"
task default: "install"
desc "Hook our dotfiles into system-standard positions."
task :install do
files_to_symlink(DOTFILES_DIRECTORY).each { |file| symlink_file(file) }
end
# Run as rake setup_file[file_name]
# Zsh will be kind of weird with the brackets, so do this:
# rake 'setup_file[.my_dot_file]'
# unless you add 'unsetopt nomatch' to .zshrc, then you're good to go without the quotes
# symlink multiple files at once
# rake setup_file['.maid .vimrc .hushlogin']
desc "Symlink arbitrary files."
task :setup_file, [:file] do |t, file|
file[:file].to_s.split.each do |single_file|
symlink_file(single_file)
end
end
def files_to_symlink(directory)
files = Dir.chdir(directory) { Dir.glob("**/*", File::FNM_DOTMATCH) }
files.select { |f| File.file? File.join(directory, f) }
end
def symlink_file(file)
source = "#{ENV["PWD"]}/#{DOTFILES_DIRECTORY}/#{file}"
target = "#{ENV["HOME"]}/#{file}"
puts "Source: #{source}"
puts "Target: #{target}"
`mkdir -p "#{File.dirname(target)}"`
if File.exist?(target) || File.symlink?(target)
puts "[Overwriting] #{target}..."
end
`ln -nfvs "#{source}" "#{target}"`
end