From bb19d19a58b8144e8203c5fadfd12da1e3ff0aa9 Mon Sep 17 00:00:00 2001 From: nirenjan Date: Tue, 13 Aug 2013 16:24:32 -0700 Subject: [PATCH] Add VimBundler script and bundles file --- VimBundler | 156 ++++++++++++++++++++++++++++++++++++++++++++++++++++ install | 75 +------------------------ vim/bundles | 24 ++++++++ vimrc | 18 ++---- 4 files changed, 187 insertions(+), 86 deletions(-) create mode 100755 VimBundler create mode 100644 vim/bundles diff --git a/VimBundler b/VimBundler new file mode 100755 index 0000000..e5ccf8a --- /dev/null +++ b/VimBundler @@ -0,0 +1,156 @@ +#!/usr/bin/env ruby +# Script to automatically install Vim bundles to ~/.vim/bundle/ +# +# See vim/bundles for a sample file + +require 'getoptlong' + +# Shut up about warnings +BUNDLE_ROOT = '/.vim/bundle/' + +def vim_bundle(bundle, tag=nil) + if $transport == 'ssh' + url = 'git@github.com:' + elsif $transport == 'https' + url = 'https://github.com/' + elsif $transport == 'git' + url = 'git://github.com/' + else + $stderr.puts "#{$an}: Unrecognized transport layer '#{transport}' (try --help)" + exit 1 + end + + if bundle =~ /^[A-Za-z0-9-]+\/[A-Za-z0-9._-]+$/ + url += bundle + '.git' + elsif bundle =~ /^[A-Za-z0-9._-]+$/ + url += 'vim-scripts/' + bundle + '.git' + else + # We are using a service other than GitHub. Specifying the URL directly + url = bundle + end + + bundle_name = bundle.sub(/^.*\//, '').sub(/\.git$/, '') + + if $dry_run + puts "URL #{url} Bundle #{bundle_name} Tag #{tag.to_s}" + return + else + dir = ENV['HOME'] + BUNDLE_ROOT + bundle_name + pwd = Dir.pwd + $VERBOSE = nil + if File.directory?(dir) + if $update # Don't update if the no-update option was passed + if File.directory?(dir + '/.git') + puts "Updating bundle #{bundle_name}..." + Dir.chdir(dir) + `git fetch` + Dir.chdir(pwd) + puts + else + $stderr.puts "#{$an}: #{bundle_name} is not a Git repository." + return + end + else + $stderr.puts "#{$an}: Skipping update for #{bundle_name}" + return + end + + else + # Directory doesn't exist, need to pull + puts "Installing bundle #{bundle_name}..." + Dir.chdir(ENV['HOME'] + BUNDLE_ROOT) + `git clone #{url} #{bundle_name}` + Dir.chdir(pwd) + puts + end + + tag ||= 'origin/HEAD' + Dir.chdir(dir) + `git stash` + `git checkout #{tag}` + `git stash pop` + Dir.chdir(pwd) + $VERBOSE = false + end +end + +opts = GetoptLong.new( + [ '--help', '-h', GetoptLong::NO_ARGUMENT ], + [ '--transport', '-t', GetoptLong::REQUIRED_ARGUMENT ], + [ '--no-update', GetoptLong::NO_ARGUMENT ], + [ '--dry-run', '-n', GetoptLong::NO_ARGUMENT ] +) + +$an = $0.sub(/^.*\//, '') +file = nil +$transport = 'ssh' +$update = true +$dry_run = false + +opts.each do |opt, arg| + case opt + when '--help' + puts <<-EOF +#{$an} manages vim bundles in ~/.vim/bundles +Usage: #{$an} [OPTIONS] FILE + +Options: + --transport, Use the specified transport layer to download git bundles. + -t