-
Notifications
You must be signed in to change notification settings - Fork 6
/
Rakefile
172 lines (138 loc) · 4.15 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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
require 'rake'
require 'fileutils'
task :install do
puts '-- Installing dotitup'
clone_it 'oh-my-zsh',
source: 'https://github.com/robbyrussell/oh-my-zsh',
destination: File.expand_path('~/.oh-my-zsh')
clone_it 'zsh-syntax-highlighting',
source: 'https://github.com/zsh-users/zsh-syntax-highlighting',
destination: current_path(
'zsh', 'plugins', 'zsh-syntax-highlighting'
)
puts '-- Linking files and folders'
link_it 'gemrc'
Rake::Task["setup_agignore"].execute
Rake::Task["setup_ctags"].execute
link_it 'zshrc'
link_it 'tmux.conf'
link_it 'custom oh my zsh',
source: 'zsh',
destination: '~/.oh-my-zsh/custom',
pre_link: lambda {
if File.exist?(File.expand_path('~/.oh-my-zsh/custom/example.zsh'))
FileUtils.rm_rf(File.expand_path('~/.oh-my-zsh/custom/'))
end
}
neovim = `which nvim`.chomp
if neovim != ''
setup_neovim
end
# vim = `which vim`.chomp
# if vim != ''
# setup_vim
# end
end
task :setup_ctags do
link_it 'ctags'
link_it 'ctags', destination: '~/.ctags.d/default.ctags'
end
task :setup_agignore do
link_it 'agignore'
end
task :setup_neovim do
setup_neovim
end
task :setup_vim do
setup_vim
end
task :parse_docs do
files = Dir['./vim/settings/*.vim'] + Dir['./vim/plugs/*.vim']
results = []
files.each do |file|
contents = File.read file
results |= contents.scan(/" ###.*?" ###/m)
end
File.open('./vim/guide/dotitup_docs.md', 'w') do |f|
results.each do |result|
result = result.split("\n").collect { |line| line.sub(/^"$/, '" ') }.join("\n")
result = result.split("\n").collect { |line| line.sub(/^" /, '') }.join("\n")
f.puts result
f.puts ''
end
end
end
task default: 'install'
private
def setup_neovim
curl_it 'vim-plug',
source: 'https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim',
destination: '~/.local/share/nvim/site/autoload/plug.vim'
link_it 'vim', destination: '~/.dotvim'
link_it 'vimrc', destination: '~/.config/nvim/init.vim'
vim = `which nvim`.chomp
vimplugs(vim)
end
def setup_vim
curl_it 'vim-plug',
source: 'https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim',
destination: current_path('vim', 'autoload', 'plug.vim')
link_it 'vim', destination: '~/.dotvim'
link_it 'vimrc'
# vim-plug installing
puts '-- vim-plug Install'
vim = `which vim`.chomp
vimplugs(vim)
end
def vimplugs(vim)
before = <<-BEF
filetype off " required
set rtp+=~/.dotvim/plugs/
call plug#begin('~/.dotvim/plugged')
BEF
after = <<-AFT
call plug#end()
filetype plugin indent on " required
AFT
middle = `grep -h "Plug " vim/plugs/*`
File.open("vimplugs.vim", "w") do |f|
f.write before
f.write middle
f.write after
end
run "#{vim} --noplugin -u vimplugs.vim +PlugInstall +qall"
run "#{vim} +PlugClean! +UpdateRemotePlugins +qall" if vim.include?('nvim')
File.unlink "vimplugs.vim"
end
def run(command)
puts "-- Running [#{command}]"
`#{command}`
end
def link_it(name, options = {})
options[:name] = name
source = options[:source] || options[:name]
destination = options[:destination] || "~/.#{source}"
destination = File.expand_path(destination)
base_destination = File.dirname(destination)
mkdir_p(base_destination) unless File.exist?(base_destination)
source = File.expand_path(source.to_s)
options[:pre_link].call if options[:pre_link]
ln_s(source, destination) unless File.exist?(destination)
end
def curl_it(name, options = {})
options[:name] = name
return if File.exist?(options[:destination])
options[:destination] = File.expand_path(options[:destination])
puts "-- Cloning #{options[:name]}"
run "curl -fLo #{options[:destination]} --create-dirs #{options[:source]}"
end
def clone_it(name, options = {})
options[:name] = name
return if File.exist?(options[:destination])
puts "-- Cloning #{options[:name]}"
run "git clone #{options[:source]} #{options[:destination]}"
end
def current_path(*args)
current_path = __dir__
File.join current_path, *args
end