Update yadr's binary to support Vundle

yadr-vim-add-plugin now supports adding vundle plugins
This commit is contained in:
Fabio Gallonetto 2013-03-17 17:10:55 +00:00
parent 5c3b05302e
commit 1836070a54
2 changed files with 64 additions and 13 deletions

47
bin/yadr/vundle.rb Normal file
View File

@ -0,0 +1,47 @@
require 'fileutils'
module Vundle
@vundles_path = File.expand_path File.join('~', '.vim', 'vundles.vim')
def self.add_plugin_to_vundle(plugin_repo)
return if contains_vundle? plugin_repo
vundles = vundles_from_file
last_bundle_dir = vundles.rindex{ |line| line =~ /^Bundle / }
vundles.insert last_bundle_dir+1, "Bundle \"#{plugin_repo}\""
write_vundles_to_file vundles
end
def self.remove_plugin_from_vundle(plugin_repo)
vundles = vundles_from_file
deleted_value = vundles.reject!{ |line| line =~ /Bundle "#{plugin_repo}"/ }
write_vundles_to_file vundles
!deleted_value.nil?
end
def self.vundle_list
vundles_from_file.select{ |line| line =~ /^Bundle .*/ }.map{ |line| line.gsub(/Bundle "(.*)"/, '\1')}
end
def self.update_vundle
system "vim --noplugin -u vim/vundles.vim -N \"+set hidden\" \"+syntax on\" +BundleClean +BundleInstall +qall"
end
private
def self.contains_vundle?(vundle_name)
File.read(@vundles_path).include?(vundle_name)
end
def self.vundles_from_file
File.read(@vundles_path).split("\n")
end
def self.write_vundles_to_file(vundles)
FileUtils.cp(@vundles_path, "#{@vundles_path}.bak")
vundle_file = File.open(@vundles_path, "w")
vundle_file.write(vundles.join("\n"))
vundle_file.close
end
end

View File

@ -1,23 +1,27 @@
#!/usr/bin/env ruby
require File.join(File.dirname(__FILE__), 'default_libs')
require File.join(File.dirname(__FILE__), 'vundle')
GitStyleBinary.command do
version "yadr-add-vim-plugin 1.0"
short_desc "Add a vim plugin from a github repo"
opt :url, "Github url (http:// or git://)", :type => String
short_desc "Add a vim plugin from a repo"
opt :url, "Repository URL (see usage)", :required => true, :type => String
banner <<-'EOS'
Usage: yadr-add-vim-plugin --url [URL]
Specify a plugin repository URL in one of the following forms:
- Custom repository URL (full URL): git://git.wincent.com/command-t.git
- Github repository (username/repo_name): robgleesson/hammer.vim.git
- Vim script repository (plugin_name): FuzzyFinder
EOS
run do |command|
unless ARGV.size==1
puts "Example: #{$0} https://github.com/robgleeson/hammer.vim.git"
else
begin
repo=command[:url]
bundle_path=repo.gsub("https://github.com/","").gsub(".git","").gsub("/","-").gsub(".vim","")
system("cd #{$yadr} && git submodule add #{repo} vim/bundle/#{bundle_path}")
rescue
puts "Sorry, couldn't parse your path: #{$!}"
end
end
repo=command.opts[:url]
repo=command.opts[:url]
puts "Adding \"#{repo}\" to the plugin list"
bundle_path=repo.gsub("https://github.com/", "")
Vundle::add_plugin_to_vundle repo
Vundle::update_vundle
end
end