Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 94 lines (72 sloc) 2.41 KB
#!/usr/bin/env ruby
#
# name : vimenv, configure vim environment
# author : Xu Xiaodong <xxdlhy@gmail.com>
# license : GPL
# created : 2012 Apr 14
# modified : 2012 Jul 08
#
require 'fileutils'
require 'optparse'
def init
conf = %w[vimrc vim]
conf.each do |item|
orig = "#{Dir.pwd}/_#{item}"
target = "#{ENV['HOME']}/.#{item}" # oops... 1.8.5 does not support Dir.home
bak = "#{target}.old"
if File.exist?(target) && ! File.symlink?(target)
puts "Backuping #{target} to #{bak}"
FileUtils.mv(target, bak)
end
FileUtils.rm(target) if File.symlink?(target)
puts "Symlinking #{orig} to #{target}"
FileUtils.symlink(orig, target)
end
end
def edit
puts "Editing Vim configuration file"
system "vim _vimrc"
end
def add(author_slash_name)
name = author_slash_name.gsub(/^.*\/(?:vim-)?(.*?)(?:[-\.]vim)?(?:-theme)?$/, '\1').downcase
src = "git://github.com/#{author_slash_name}.git"
desc = "_vim/bundle/#{name}"
puts "Adding #{src} to #{desc}"
system "git submodule add #{src} #{desc}"
end
def remove(name)
path = "_vim/bundle/#{name.downcase}"
git_path = ".git/modules/#{path}"
files = [".git/config", ".gitmodules"]
puts "Removing #{path}"
system "git rm --cached #{path} >/dev/null"
files.each { |file| system "git config -f #{file} --remove-section submodule.#{path}" }
FileUtils.rmtree(path)
FileUtils.rmtree(git_path)
end
def update
puts "Updating Vim plugins"
arg = ["init", "update", "foreach git pull origin master"]
arg.each { |elt| system "git submodule #{elt}" }
end
def list
bundle = Dir.entries('_vim/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