Skip to content

Instantly share code, notes, and snippets.

@marcusbaguley
Created August 12, 2011 03:42
Show Gist options
  • Save marcusbaguley/1141394 to your computer and use it in GitHub Desktop.
Save marcusbaguley/1141394 to your computer and use it in GitHub Desktop.
vim bundle script with pathogen and bundles
#!/usr/bin/env ruby
# stolen and adapted from
# https://raw.github.com/dsummersl/dotvim/master/update_bundles.rb
# http://tammersaleh.com/posts/the-modern-vim-config-with-pathogen
vim_command = '/usr/bin/vim'
git_command = 'git'
hg_command = 'hg'
# Git Plugins
# Each plugin can be configured thusly:
#
# URL: The plugin location. This supports three types:
# - git : a git plugin. Mostly on github.com?
# Example: ["git://github.com/sjl/gundo.vim.git"],
# ---
# This requires the 'git' command to be on your machine. It just
# does a git clone.
# - mercurial : an hg plugin. Probably bitbucket.org? Requires an hg client in your path.
# Example: ["hg://bitbucket.org/ns9tks/vim-fuzzyfinder"],
# - vim : a vim.org hosted plugin. DEPRECATED (use the github repository instead! (ie, ["git://github.com/vim-scripts/SCRIPTNAME.vim"])
# Example: ["vim://align-294", "10110"],
# ---
# The first string is the name of the plugin.
# The second string corresponds to the # (URL?src_id) you see
# for the specific version you wanna download. For instance:
#
# For the script: http://www.vim.org/scripts/script.php?script_id=30
# The latest version is 1.13, and the src_id of the link is
# http://www.vim.org/scripts/download_script.php?src_id=9196
# so 9196 is what I'd put here.
#
# lambda (optional): you can supply a lambda function at the end of any array
# to do any post cleanup/install action.. The directory you are currently in
# is the bundle/<name> (that you provided here). Example:
#
bundles = [
["git://github.com/scrooloose/nerdtree.git"],
["git://github.com/timcharper/textile.vim.git"],
["git://github.com/tpope/vim-git.git"],
["git://github.com/tpope/vim-markdown.git"],
["git://github.com/tpope/vim-rails.git"],
["git://github.com/tpope/vim-repeat.git"],
["git://github.com/tpope/vim-surround.git"],
["git://github.com/tpope/vim-vividchalk.git"],
["git://github.com/tsaleh/vim-align.git"],
["git://github.com/tsaleh/vim-shoulda.git"],
["git://github.com/tsaleh/vim-supertab.git"],
["git://github.com/tsaleh/vim-tcomment.git"],
["git://github.com/vim-ruby/vim-ruby.git"],
["git://github.com/wincent/Command-T"],
["vim://index-search-7062", "7062"],
["vim://yank-ring-13554", "13554"],
["vim://ruby-test-15911", "15911"],
]
require 'fileutils'
require 'open-uri'
bundles_dir = File.join(File.dirname(__FILE__), "bundle")
FileUtils.cd(bundles_dir)
trash = ARGV.include?('--trash')
bundles.each do |script|
url = script[0]
puts url
if (url.start_with? 'git')
dir = url.split('/').last.sub(/\.git$/, '')
if File.exists?(dir)
if !trash
puts " Skipping"
else
FileUtils.rm_rf dir
end
next
end
puts " Unpacking #{url} into #{dir}"
`#{git_command} clone #{url} #{dir}`
end
if (url.start_with? 'hg')
url = script[0].gsub(/^hg:/,"http:")
dir = url.split('/').last
if File.exists?(dir)
if !trash
puts " Skipping"
else
FileUtils.rm_rf dir
end
next
end
puts " Unpacking #{url} into #{dir}"
`#{hg_command} clone #{url} #{dir}`
end
if (url.start_with? 'vim')
name = script[0].gsub(/^vim:\/\//,"")
script_id = script[1]
if !trash && File.exists?(name)
puts " Skipping"
next
end
puts "Setup & Download #{name}"
FileUtils.mkdir_p(name)
FileUtils.cd(name)
f = open("http://www.vim.org/scripts/download_script.php?src_id=#{script_id}")
local_file = f.meta["content-disposition"].gsub(/attachment; filename=/,"")
if local_file.end_with? 'vim'
FileUtils.mkdir_p(File.dirname("plugin"))
FileUtils.cd("plugin")
end
puts " Writing #{local_file}"
File.open(local_file, "w") do |file|
file << f.read
end
if local_file.end_with? 'zip'
puts " Unzip"
%x(unzip #{local_file})
end
if local_file.end_with? 'vba.gz'
puts " Vimball Gzip"
%x(gunzip #{local_file})
# launch vim and make it process the vimball the right way:
local_folder = name
unzipped_file = local_file.gsub(/.gz/,"")
system("cd ../.. ; #{vim_command} +\"e bundle/#{local_folder}/#{unzipped_file}|UseVimball ~/.vim/bundle/#{local_folder}\"")
elsif local_file.end_with? 'vba.tar.gz'
puts " Vimball Tar Gzip"
%x(tar zxf #{local_file})
# launch vim and make it process the vimball the right way:
local_folder = name
unzipped_file = local_file.gsub(/.tar.gz/,"")
system("cd ../.. ; #{vim_command} +\"e bundle/#{local_folder}/#{unzipped_file}|UseVimball ~/.vim/bundle/#{local_folder}\"")
elsif local_file.end_with? 'tar.gz'
puts " Tar Gunzip"
%x(tar zxf #{local_file})
elsif local_file.end_with? '.gz'
puts " Gunzip"
%x(gunzip #{local_file})
end
if local_file.end_with? 'vim'
FileUtils.cd("..")
end
# do any custom code.
if script.size == 3
puts " Custom setup"
script[2].call
end
FileUtils.cd("..")
else
FileUtils.cd(dir)
if script.size == 2
puts " Custom setup"
script[1].call
end
FileUtils.cd("..")
end
end
# vim:ft=ruby:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment