Update yadr's binary to support Vundle
yadr-vim-add-plugin now supports adding vundle plugins
This commit is contained in:
parent
5c3b05302e
commit
1836070a54
47
bin/yadr/vundle.rb
Normal file
47
bin/yadr/vundle.rb
Normal 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
|
@ -1,23 +1,27 @@
|
|||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
require File.join(File.dirname(__FILE__), 'default_libs')
|
require File.join(File.dirname(__FILE__), 'default_libs')
|
||||||
|
require File.join(File.dirname(__FILE__), 'vundle')
|
||||||
|
|
||||||
GitStyleBinary.command do
|
GitStyleBinary.command do
|
||||||
version "yadr-add-vim-plugin 1.0"
|
version "yadr-add-vim-plugin 1.0"
|
||||||
|
|
||||||
short_desc "Add a vim plugin from a github repo"
|
short_desc "Add a vim plugin from a repo"
|
||||||
opt :url, "Github url (http:// or git://)", :type => String
|
|
||||||
|
|
||||||
|
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|
|
run do |command|
|
||||||
unless ARGV.size==1
|
repo=command.opts[:url]
|
||||||
puts "Example: #{$0} https://github.com/robgleeson/hammer.vim.git"
|
repo=command.opts[:url]
|
||||||
else
|
puts "Adding \"#{repo}\" to the plugin list"
|
||||||
begin
|
bundle_path=repo.gsub("https://github.com/", "")
|
||||||
repo=command[:url]
|
Vundle::add_plugin_to_vundle repo
|
||||||
bundle_path=repo.gsub("https://github.com/","").gsub(".git","").gsub("/","-").gsub(".vim","")
|
Vundle::update_vundle
|
||||||
system("cd #{$yadr} && git submodule add #{repo} vim/bundle/#{bundle_path}")
|
|
||||||
rescue
|
|
||||||
puts "Sorry, couldn't parse your path: #{$!}"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user