From fd8e3b6e50220b1dfdf97779758eb31054f63f45 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Thu, 3 Nov 2011 10:16:08 -0400 Subject: [PATCH] initial commit, works like fun --- .gitignore | 4 + Gemfile | 4 + Rakefile | 1 + bin/macvim-buddy | 161 ++++++++++++++++++++++++++++++++++++ lib/macvim-buddy.rb | 7 ++ lib/macvim-buddy/version.rb | 5 ++ macvim-buddy.gemspec | 26 ++++++ 7 files changed, 208 insertions(+) create mode 100644 .gitignore create mode 100644 Gemfile create mode 100644 Rakefile create mode 100755 bin/macvim-buddy create mode 100644 lib/macvim-buddy.rb create mode 100644 lib/macvim-buddy/version.rb create mode 100644 macvim-buddy.gemspec diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4040c6c --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +*.gem +.bundle +Gemfile.lock +pkg/* diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..370b6bc --- /dev/null +++ b/Gemfile @@ -0,0 +1,4 @@ +source "http://rubygems.org" + +# Specify your gem's dependencies in macvim-buddy.gemspec +gemspec diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..2995527 --- /dev/null +++ b/Rakefile @@ -0,0 +1 @@ +require "bundler/gem_tasks" diff --git a/bin/macvim-buddy b/bin/macvim-buddy new file mode 100755 index 0000000..9a69824 --- /dev/null +++ b/bin/macvim-buddy @@ -0,0 +1,161 @@ +#!/usr/bin/env ruby + +require 'thor' +require 'pathname' +require 'rainbow' + +class MacVimBuddy < Thor + desc "build-from-git", "Build the latest MacVim HEAD from GitHub" + def build_from_git + ensure_which :port, :git, :make + + with_system_ruby do + system %{bash -c "cd /tmp && rm -Rf macvim && git clone git://github.com/b4winckler/macvim.git"} + + if is_macports = %x{which iconv}['/opt/local'] + with_sudo { "port deactivate -f libiconv" } + end + + system %{bash -c "cd /tmp/macvim/src && ./configure --with-features=huge --enable-rubyinterp --enable-pythoninterp --enable-perlinterp --enable-cscpe && make"} + + if is_macports + with_sudo { "port activate libiconv" } + end + + system %{cp -Rpv /tmp/macvim/src/MacVim/build/Release/MacVim.app /Applications} + + system %{/Applications/MacVim.app/Contents/MacOS/Vim --version} + end + end + + class Pathogen < Thor + BUNDLE_PATH = Pathname(File.expand_path('~/.vim/bundle')) + MODULES_PATH = File.expand_path('~/.gitmodules') + + class GitSubmodule + class << self + def read(file) + submodules = [] + submodule = nil + + lines = File.readlines(file) + + lines.each do |line| + case line + when %r{submodule "(.+)"} + submodule = new($1) + submodules << submodule + when %r{path\s*=\s*(.+)} + submodule.path = $1 + when %r{url\s*=\s*(.+)} + submodule.url = $1 + end + end + + submodules + end + end + + attr_reader :name + attr_accessor :path, :url + + def initialize(name) + @name = name + end + + def to_s + <<-GIT +[submodule "#{name}"] + path = #{path} + url = #{url} +GIT + end + end + + desc "pathogen install GIT_REPO", "Install a plugin from a git repo" + def install(git_repo) + ensure_bundle + + system %{bash -c "cd ~ && git submodule add -f #{git_repo} .vim/bundle/#{repo_name(git_repo)}"} + puts "#{repo_name(git_repo)} installed" + end + + desc "pathogen update", "Update all Pathogen repos" + def update + system %{git submodule update} + end + + desc "pathogen uninstall NAME", "Uninstall a plugin by name" + def uninstall(name) + system %{bash -c "cd ~ && git rm -f .vim/bundle/#{name} ; git rm --cached .vim/bundle/#{name} ; rm -Rf .vim/bundle/#{name}"} + + File.open(tmp = File.expand_path('~/.gitmodules-tmp'), 'wb') { |fh| modules.reject { |mod| mod.name == name }.each { |mod| fh.print mod.to_s } } + FileUtils.mv tmp, MODULES_PATH + + puts "#{name} uninstalled" + end + + desc "pathogen list", "List all installed plugins" + def list + longest_name = modules.collect { |mod| mod.name.length }.max + + modules.each do |mod| + puts "#{mod.name.ljust(longest_name).foreground(:green)} : #{mod.path.foreground(:yellow)} (#{mod.url.foreground(:blue)})" + end + end + + no_tasks do + def ensure_bundle + BUNDLE_PATH.mkpath + end + + def repo_name(repo) + repo.split('/').last.gsub('.git', '') + end + + def modules + @modules ||= GitSubmodule.read(MODULES_PATH) + end + end + end + + desc "pathogen ", "Pathogen commands" + subcommand 'pathogen', Pathogen + + no_tasks do + def ensure_which(*commands) + commands.flatten.each do |command| + %x{which #{command} 2>/dev/null} + raise NotFoundError.new(command) if $?.exitstatus != 0 + end + end + + def with_system_ruby + oenv = ENV.to_hash + + %w{GEM_HOME RUBY_VERSION MY_RUBY_HOME GEM_PATH}.each { |key| ENV.delete(key) } + ENV['PATH'] = ENV['PATH'].split(':').reject { |path| path['.rvm'] }.join(":") + + yield + + ENV.replace(oenv) + end + + def with_sudo + if !@password + system "stty -echo" + $stdout.print "sudo password: " + $stdout.flush + @password = $stdin.readline.strip + system "stty echo" + $stdout.puts + end + + system %{echo "#{@password}" | sudo -p '' -S #{yield}} + end + end + + class NotFoundError < StandardError ; end +end + +MacVimBuddy.start diff --git a/lib/macvim-buddy.rb b/lib/macvim-buddy.rb new file mode 100644 index 0000000..bff04b8 --- /dev/null +++ b/lib/macvim-buddy.rb @@ -0,0 +1,7 @@ +require "macvim-buddy/version" + +module Macvim + module Buddy + # Your code goes here... + end +end diff --git a/lib/macvim-buddy/version.rb b/lib/macvim-buddy/version.rb new file mode 100644 index 0000000..7829a43 --- /dev/null +++ b/lib/macvim-buddy/version.rb @@ -0,0 +1,5 @@ +module Macvim + module Buddy + VERSION = "0.0.1" + end +end diff --git a/macvim-buddy.gemspec b/macvim-buddy.gemspec new file mode 100644 index 0000000..7db334b --- /dev/null +++ b/macvim-buddy.gemspec @@ -0,0 +1,26 @@ +# -*- encoding: utf-8 -*- +$:.push File.expand_path("../lib", __FILE__) +require "macvim-buddy/version" + +Gem::Specification.new do |s| + s.name = "macvim-buddy" + s.version = Macvim::Buddy::VERSION + s.authors = ["John Bintz"] + s.email = ["john@coswellproductions.com"] + s.homepage = "" + s.summary = %q{A bunch of useful things for Vim and specifically MacVim} + s.description = %q{A bunch of useful things for Vim and specifically MacVim} + + s.rubyforge_project = "macvim-buddy" + + s.files = `git ls-files`.split("\n") + s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") + s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } + s.require_paths = ["lib"] + + # specify any dependencies here; for example: + # s.add_development_dependency "rspec" + s.add_runtime_dependency "thor" + s.add_runtime_dependency "rainbow" +end +