-
Notifications
You must be signed in to change notification settings - Fork 0
/
vimenv
executable file
·97 lines (76 loc) · 2.1 KB
/
vimenv
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
#!/usr/bin/env ruby
# coding: utf-8
#
# name: vimenv
# author: Xu Xiaodong <xxdlhy@gmail.com>
# license: GPL
# created: 2012 Apr 14
# modified: 2012 Apr 17
#
require 'fileutils'
require 'optparse'
def init
conf = %w[vimrc vim]
conf.each do |item|
orig = Dir.pwd + '/_' + item
target = Dir.home + '/.' + item
bak = target + '.bak'
if File.exist?(target) && ! File.symlink?(target)
puts "Backuping #{target} to #{bak}"
FileUtils.mv(target, bak)
end
if File.symlink?(target)
FileUtils.rm(target)
end
puts "Symlinking #{orig} to #{target}"
FileUtils.symlink(orig, target, force: true)
end
end
def edit
puts "Editing Vim configuration file"
system "vim _vimrc"
end
def add(name)
src = 'git://github.com/vim-scripts/' + name + '.git'
desc = 'bundle/' + name
puts "Adding #{src} to #{desc}"
system "git submodule add #{src} #{desc}"
end
def remove(name)
path = 'bundle/' + name
files = [".git/config", ".gitmodules"]
puts "Removing #{path}"
system "git rm --cached #{path} >/dev/null"
files.each do |file|
system "git config -f #{file} --remove-section submodule.#{path}"
end
FileUtils.rmtree(path)
end
def update
puts "Updating Vim plugins"
arg = ["init", "update", "foreach git pull origin master"]
arg.each do |elt|
system "git submodule #{elt}"
end
end
def list
bundle = Dir.entries('bundle')
plugins = bundle[2, bundle.size].sort
plugins.each { |name| puts "Installed #{name}" }
total = plugins.size
puts "Total #{total} plugins"
end
opts = OptionParser.new
opts.on("-i", "--init", "Initialize Vim environment") { init }
opts.on("-e", "--edit", "Edit Vim configuration file") { edit }
opts.on("-a", "--add NAME", "Add Vim plugins") { |name| add(name) }
opts.on("-r", "--remove NAME", "Remove Vim plugins") { |name| remove(name) }
opts.on("-u", "--update", "Update Vim plugins") { update }
opts.on("-l", "--list", "List Vim plugins") { list }
opts.on("-h", "--help", "Show help") { puts opts.to_s }
if ARGV.empty?
puts opts.to_s
else
opts.parse(*ARGV)
end
# vim: ai:et:ts=2:sw=2:sts=2:tw=78:ft=ruby