forked from ryanb/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathRakefile
143 lines (120 loc) · 3.7 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
require 'rake'
require 'erb'
require 'digest/md5'
PLATFORM_IS_OSX = (Object::RUBY_PLATFORM =~ /darwin/i) ? true : false
desc "install the dot files into user's home directory"
task :install do
initialize_submodules
create_local_files
link_files(Dir.pwd, ENV['HOME'], :prefix => '.')
system('bin/install_powerline_fonts.sh')
setup_fzf
setup_neovim
setup_vim_plugins
end
desc "install dotfiles without any prompts, assuming overwrite"
task :promptless_install do
initialize_submodules
$promptless = true
create_local_files
link_files(Dir.pwd, ENV['HOME'], :prefix => '.', :replace_all => true)
setup_fzf
setup_neovim
setup_vim_plugins
end
def create_local_files
system('touch ~/.vimrc.local')
system('touch ~/.gvimrc.local')
end
def setup_fzf
system('~/.fzf/install')
end
def setup_vim_plugins
if File.exists?('vim/bundle/vimproc.vim/Makefile') && Dir.glob('vim/bundle/vimproc.vim/lib/vimproc_*.so').empty?
puts 'Building vimproc'
system('cd vim/bundle/vimproc.vim && make')
end
if File.exists?('vim/bundle/YouCompleteMe') && !File.exists?('vim/bundle/YouCompleteMe/third_party/ycmd/ycm_core.so') && which('python')
puts 'Setting up YouCompleteMe'
system('cd vim/bundle/YouCompleteMe/ && ./install.py --tern-completer')
end
end
def setup_neovim
system('mkdir -p ~/.config')
system('ln -ns ~/.vim ~/.config/nvim')
system('ln -s ~/.vimrc ~/.config/nvim/init.vim')
end
def link_files(source_dir, destination_dir, opts)
prefix = opts[:prefix] || ''
replace_all = opts[:replace_all] || false
copy_file = opts[:copy_file] || false
files = Dir.chdir(source_dir) do
Dir.glob('*')
end
files.each do |filename|
next if %w[Rakefile README.md LICENSE].include? filename
source_file = File.join(source_dir, filename)
destination_file = File.join(destination_dir, "#{prefix}#{filename.sub('.erb', '')}")
if File.exist?(destination_file)
if File.identical? source_file, destination_file
puts "identical #{destination_file}"
elsif copy_file && file_hash(source_file) == file_hash(destination_file)
puts "identical #{destination_file}"
elsif replace_all
replace_file(source_file, destination_file, copy_file)
else
print "overwrite #{destination_file}? [ynaq] "
case $stdin.gets.chomp
when 'a'
replace_all = true
replace_file(source_file, destination_file, copy_file)
when 'y'
replace_file(source_file, destination_file, copy_file)
when 'q'
exit
else
puts "skipping #{destination_file}"
end
end
elsif copy_file
replace_file(source_file, destination_file, copy_file)
else
link_file(source_file, destination_file)
end
end
end
def link_file(source, destination)
if source =~ /.erb$/
File.open(destination, 'w') do |new_file|
new_file.write ERB.new(File.read(source)).result(binding)
end
else
puts "linking #{destination}"
system %Q{ln -s "#{source}" "#{destination}"}
end
end
def replace_file(source, destination, copy = false)
system %Q{rm -rf "#{destination}"}
if copy
puts "writing #{destination}"
system %Q{cp "#{source}" "#{destination}"}
else
link_file(source, destination)
end
end
def initialize_submodules
system %Q{git submodule update --init --recursive && git submodule status}
end
def file_hash(filename)
Digest::MD5.hexdigest(IO.read(filename))
end
def which(cmd)
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
exts.each { |ext|
exe = File.join(path, "#{cmd}#{ext}")
return exe if File.executable?(exe) && !File.directory?(exe)
}
end
return nil
end