From 1836070a5421b0faf0f61996417cbc044a2ee657 Mon Sep 17 00:00:00 2001 From: Fabio Gallonetto Date: Sun, 17 Mar 2013 17:10:55 +0000 Subject: [PATCH] Update yadr's binary to support Vundle yadr-vim-add-plugin now supports adding vundle plugins --- bin/yadr/vundle.rb | 47 ++++++++++++++++++++++++++++++++++++ bin/yadr/yadr-vim-add-plugin | 30 +++++++++++++---------- 2 files changed, 64 insertions(+), 13 deletions(-) create mode 100644 bin/yadr/vundle.rb diff --git a/bin/yadr/vundle.rb b/bin/yadr/vundle.rb new file mode 100644 index 0000000..bd485a1 --- /dev/null +++ b/bin/yadr/vundle.rb @@ -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 diff --git a/bin/yadr/yadr-vim-add-plugin b/bin/yadr/yadr-vim-add-plugin index 41a2fbb..01e98c7 100755 --- a/bin/yadr/yadr-vim-add-plugin +++ b/bin/yadr/yadr-vim-add-plugin @@ -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