-
Notifications
You must be signed in to change notification settings - Fork 2
/
Rakefile
156 lines (133 loc) · 3.61 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
require 'rake'
def log(message)
puts with_color("\n######### #{message} #########", 93)
end
def with_color(message, colorcode)
"\033[#{colorcode}m#{message}\033[0m"
end
def inst_message(arg, add_m)
"Installing #{arg} #{add_m}".strip
end
def argument_handler(def_args, opt_arg, creation_args, orig_m, add_m = '')
args = [def_args]
if opt_arg
log(inst_message(opt_arg, add_m))
args << opt_arg
else
log(inst_message(orig_m, add_m))
end
Linker.new(*args).create_from(*creation_args)
end
desc "manages all submodules"
task :submodules do
log('Updating submodules')
system 'git submodule update --init --recursive'
end
desc "installs plugins in your ~/.janus directory"
task :plugins, :sel do |t, args|
argument_handler('.janus', args['sel'], [t.to_s, false], t.to_s, 'to janus')
end
desc "installs dot files and directories in home directory"
task :dots, :sel do |t, args|
argument_handler('', args['sel'], ['.'], 'Dotfiles')
end
desc "installs snippets in the snippets directory"
task :snippets do
log('Using custom snippets')
snip_dir = '.vim/janus/vim/tools/vim-snippets'
Linker.new("#{snip_dir}/UltiSnips").create_from("snippets/ultisnips")
end
desc "updates the fonts cache"
task :fonts do
log('Updating font cache')
exec 'fc-cache -vf ~/.fonts'
end
desc 'compiles several ressources'
task :compile do
log('Compiling YouCompleteMe')
Dir.chdir('plugins/YouCompleteMe') do
system './install.sh'
end
log('Compiling xcape')
Dir.chdir('util/xcape') do
system 'make'
system 'sudo make install'
end
log('Compiling tig')
Dir.chdir('util/tig') do
system 'make prefix=/usr/local'
system 'sudo make install prefix=/usr/local'
end
log('Compiling tidy-html5')
Dir.chdir('util/tidy-html5') do
system 'make -C build/gmake'
system 'sudo make install -C build/gmake'
end
end
desc 'install synaptics configuration for T440s'
task :synaptics do
Dir.chdir('t440s') do
exec 'sudo mkdir -p /etc/X11/xorg.conf.d && \
sudo cp 50-synaptics.conf /etc/X11/xorg.conf.d/'
end
end
task default: [:submodules, :dots, :plugins, :snippets, :fonts ]
class Linker
def initialize(path = "", selector = '*', exclusions = %w{ install.sh Rakefile README.md })
@path = File.join(ENV["HOME"], path)
@selector = selector
@exclusions = exclusions
# dot dotfiles
@prefix = (path.empty? ? "." : "")
end
def create_from(dir, no_dir = true)
@replace_all = false
Dir.chdir("#{Dir.pwd}/#{dir}") do
Dir[@selector].each do |file|
next if @exclusions.include?(file) || (no_dir && non_linkable_directory(file))
create_links(file)
end
end
end
def non_linkable_directory(file)
File.directory?(file) if non_linkable.include?(file)
end
def non_linkable
%w{ plugins snippets util t440s }
end
def full_path(file)
File.join(@path, file)
end
def create_links(file)
file = "#{@prefix}#{file}"
if File.exist?(full_path(file))
if @replace_all
replace_file(file)
else
print "overwrite #{full_path(file)}? [ynaq] "
case $stdin.gets.chomp
when 'a'
@replace_all = true
replace_file(file)
when 'y'
replace_file(file)
when 'q'
exit
else
puts "skipping #{full_path(file)}"
end
end
else
link_file(file)
end
end
def replace_file(file)
system %Q{rm "#{full_path(file)}"}
link_file(file)
end
def link_file(file)
puts "linking #{full_path(file)}"
unprefixed = file.sub(/^#{@prefix}/, "")
system %Q{ln -s "#{Dir.pwd}/#{unprefixed}" "#{full_path(file)}"}
end
end