-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
79 lines (58 loc) · 1.94 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
# Using Zach Holman's Rakefile
# https://raw.github.com/holman/dotdot_files/master/Rakefile
require 'rake'
desc "Link and run dotdot_files"
task :install do
if !File.exists?("#{ENV['HOME']}/.oh-my-zsh")
puts 'Oh My Zsh must be installed first'
exit
end
puts "Enter a hostname for this computer:"
hostname = STDIN.gets.gsub("\n", "")
`scutil --set ComputerName "#{hostname}"`
`scutil --set HostName "#{hostname}"`
`scutil --set LocalHostName "#{hostname.gsub(/\ /, '-')}"`
dot_files = Dir.glob('*/**{.symlink}')
dot_files.each do |dot_file|
file = dot_file.split('/').last.split('.symlink').last
target = "#{ENV["HOME"]}/.#{file}"
# Symlink zsh files to oh-my-zsh custom dir
target = "#{ENV["HOME"]}/.oh-my-zsh/custom/#{file}" if File.extname(file) == ".zsh"
if File.exists?(target) || File.symlink?(target)
puts "File #{target} already exists, backup (b) or delete (d)?"
backup = false
case STDIN.gets.chomp.downcase
when 'b' then backup = true
end
`mv "#{target}" "#{target}.backup"` if backup == true
FileUtils.rm_rf(target)
end
`ln -s "$PWD/#{dot_file}" "#{target}"`
end
puts "Run shell files? [Y/n]"
case STDIN.gets.chomp.downcase
when 'n' then exit
end
shell_files = Dir.glob('*/**{.sh}')
shell_files.each do |file|
puts "Running shell file #{file}"
`sh #{file}`
end
end
task :uninstall do
dot_files = Dir.glob('*/**{.symlink}')
dot_files.each do |dot_file|
file = dot_file.split('/').last.split('.symlink').last
target = "#{ENV["HOME"]}/.#{file}"
target = "#{ENV["HOME"]}/.oh-my-zsh/custom/#{file}" if File.extname(file) == ".zsh"
if File.symlink?(target)
puts "Removing #{target}..."
FileUtils.rm_rf(target)
end
# Restore any backups made
if File.exists?("#{ENV['HOME']}/.#{file}.backup")
`mv #{ENV['HOME']}/.#{file}.backup #{target}`
end
end
end
task :default => 'install'