-
Notifications
You must be signed in to change notification settings - Fork 9
/
Rakefile
134 lines (105 loc) · 3.16 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
task :default => "install"
namespace "configs" do
IGNORE = %w(Rakefile README.md bin)
SPECIAL_CONFIG = {
"ripgreprc" => {
symlink: "ripgreprc",
dest: "~/.config/ripgrep/",
},
"init.lua" => {
symlink: "init.lua",
dest: "~/.config/nvim"
},
"Tomorrow-Night.vim" => {
symlink: "Tomorrow-Night.vim",
dest: "~/.config/nvim/colors"
},
"lua" => {
symlink: "lua",
dest: "~/.config/nvim/",
},
}
desc "symlink files into home directory"
task :install do
working_dir = File.dirname(__FILE__)
for_each_dotfile(working_dir) do |file, dotfile_path|
convert_to_backup(dotfile_path)
FileUtils.ln_s(file, dotfile_path)
end
end
desc "remove symlinks, add old files"
task :uninstall do
working_dir = File.dirname(__FILE__)
for_each_dotfile(working_dir) do |_, dotfile_path|
FileUtils.rm_rf(dotfile_path) if File.symlink?(dotfile_path) || File.exist?(dotfile_path)
restore_backup(dotfile_path)
end
end
def for_each_dotfile(dir, &block)
my_dotfiles = Dir.glob(File.join(dir,"*"))
my_dotfiles.each do |file|
filename = File.basename(file)
next if IGNORE.include?(filename)
config = SPECIAL_CONFIG[filename] || { dest: "~", symlink: ".#{filename}" }
dest = File.expand_path(config[:dest])
FileUtils.mkdir_p(dest) unless File.directory?(dest)
dotfile_path = File.join(dest, config[:symlink])
yield file, dotfile_path
end
end
end
namespace "plugins" do
VIM_COMMAND = "nvim"
desc "install prereqs"
task :install do
puts "Installing vim plugins"
system('nvim --headless "+Lazy! sync" +qa | tee /tmp/plug_install.txt')
end
desc "remove prereqs"
task :uninstall do
puts "Removing vim plugins"
FileUtils.rm_rf(VIM_DIR)
FileUtils.rm_rf(VIM_FILE)
restore_backup(VIM_DIR)
restore_backup(VIM_FILE)
end
end
namespace "scripts" do
INSTALL_DIR = File.expand_path("~/.bin")
SCRIPT_DIR = File.expand_path(File.dirname(__FILE__))
desc "install scripts"
task :install do
bin_scripts = Dir.glob(File.join(SCRIPT_DIR,"bin","*"))
bin_scripts.each { |script| chmod( 0755, script) }
if File.exist?(INSTALL_DIR)
if File.symlink?(INSTALL_DIR)
puts "WARNING: Bin symlink was present on install"
rm(INSTALL_DIR)
else
puts "ERROR: Your bin folder is screwed up; can\"t install! #{INSTALL_DIR}"
exit
end
end
FileUtils.ln_s("#{SCRIPT_DIR}/bin", INSTALL_DIR)
end
desc "uninstall scripts"
task :uninstall do
if File.symlink?(INSTALL_DIR)
rm(INSTALL_DIR)
elsif File.exist?(INSTALL_DIR)
puts "WARNING: Leaving a non-empty bin directory behind"
end
end
end
desc "install everything"
task :install => ["scripts:install", "configs:install", "plugins:install"]
desc "uninstall everything"
task :uninstall => ["plugins:uninstall", "configs:uninstall", "scripts:uninstall"]
task "all:install" => [:install]
def convert_to_backup(file)
File.rename(file, "#{file}.bak") if File.exist?(file)
end
def restore_backup(file)
backup_file = "#{file}.bak"
File.rename(backup_file, file) if File.exist?(backup_file)
end