-
Notifications
You must be signed in to change notification settings - Fork 0
/
vbinstall
executable file
·56 lines (47 loc) · 1.52 KB
/
vbinstall
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
#!/usr/bin/env ruby
require 'fileutils'
# helper script to create a vim bundle in ~/.vim/bundle
unless ARGV.size >= 2
puts "must provide:
NAME
VIM_RESOURCE (.vim,.zip,.git URL,wget URL)
[PATH (location to install .vim - only needed for .vim)]
"
exit 1
end
bundle_name = ARGV[0]
vim_resource = ARGV[1]
install_path = ARGV[2] || 'plugin'
BUNDLE_DIR = "#{ENV['HOME']}/.vim/bundles-available/#{bundle_name}"
# if resource is a git repo, just checkout and be done
if vim_resource =~ /^http(s)?:.*\.git$/
`git clone #{vim_resource} #{BUNDLE_DIR}`
exit 0
end
# download resource if type is URL
if vim_resource =~ /^http(s)?:.*/
download = "/tmp/#{bundle_name}_vim_bundle"
`wget -q -O #{download} #{vim_resource}`
vim_resource = download
end
# determine type and handle appropriately
resource_type = `file -ib #{vim_resource}`
case resource_type
when /application.zip/
# unzip file into bundle dir
`unzip #{vim_resource} -d #{BUNDLE_DIR}`
when /text.plain/
FileUtils.mkdir_p( "#{BUNDLE_DIR}" )
# determine if .vim or .vba
# if it is a vba script, launch vim, and extract vimball into bundle dir
# if it is a vim script, just move to appropriate directory
`head #{vim_resource} | grep UseVimball`
if $?.success?
`cd #{BUNDLE_DIR} && ex #{vim_resource} -c ':UseVimball #{BUNDLE_DIR}' -c ':q'`
else
FileUtils.mkdir_p( "#{BUNDLE_DIR}/#{install_path}" )
FileUtils.mv( vim_resource, "#{BUNDLE_DIR}/#{install_path}/#{bundle_name}.vim" )
end
else
puts "unknown vim resource type: #{resource_type}"
end