Permalink
Browse files

improve compiling CommandT considering Homebrew-installed MacVim

  • Loading branch information...
1 parent 3584763 commit 252b3cc136c9f2555d4222f60536a48c5ed8ed66 @mislav committed Jan 3, 2012
Showing with 49 additions and 10 deletions.
  1. +49 −10 Rakefile
View
@@ -1,9 +1,11 @@
task :default => [:tmp_dirs, :update, :command_t, :link]
+desc %(Bring bundles up to date)
task :update do
sh "git submodule update --init"
end
+desc %(Make ~/.vimrc and ~/.gvimrc symlinks)
task :link do
%w[vimrc gvimrc].each do |script|
dotfile = File.join(ENV['HOME'], ".#{script}")
@@ -20,16 +22,53 @@ task :tmp_dirs do
mkdir_p "_temp"
end
-task :command_t do
- puts "Compiling Command-T plugin..."
+desc %(Compile Command-T plugin)
+task :command_t => :macvim_check do
+ vim = which('mvim') || which('vim') or abort "vim not found on your system"
+ ruby = read_ruby_version(vim)
+
Dir.chdir "bundle/command-t/ruby/command-t" do
- # first try to read which ruby version is vim compiled against
- read_version = %{require "rbconfig"; print File.join(RbConfig::CONFIG["bindir"], RbConfig::CONFIG["ruby_install_name"])}
- ruby = `vim --cmd 'ruby #{read_version}' --cmd 'q' 2>&1 >/dev/null | grep -v 'Vim: Warning'`.strip
- # fall back to system rubies
- ruby = %w[/usr/bin/ruby1.8 /usr/bin/ruby].find {|rb| File.executable? rb } || 'ruby' if ruby.empty?
- cmd = Array(ruby) + %w[extconf.rb]
- sh(*cmd)
- sh "make clean && make"
+ if ruby
+ puts "Compiling Command-T plugin..."
+ sh(*Array(ruby).concat(%w[extconf.rb]))
+ sh "make clean && make"
+ else
+ warn color('Warning:', 31) + " Can't compile Command-T, no ruby support in #{vim}"
+ sh "make clean"
+ end
+ end
+end
+
+task :macvim_check do
+ if mvim = which('mvim') and '/usr/bin/vim' == which('vim')
+ warn color('Warning:', 31) + " You have MacVim installed, but `vim` still opens system Vim."
+ warn "To use MacVim version when you invoke `vim`: " + color("$ ln -s mvim #{File.dirname(mvim)}/vim", 37)
+ end
+end
+
+def color msg, code
+ if $stderr.tty? then "\e[1;#{code}m#{msg}\e[m"
+ else msg
+ end
+end
+
+# Read which ruby version is vim compiled against
+def read_ruby_version vim
+ script = %{require "rbconfig"; print File.join(RbConfig::CONFIG["bindir"], RbConfig::CONFIG["ruby_install_name"])}
+ version = `#{vim} --nofork --cmd 'ruby #{script}' --cmd 'q' 2>&1 >/dev/null | grep -v 'Vim: Warning'`.strip
+ version unless version.empty? or version.include?("command is not available")
+end
+
+# Cross-platform way of finding an executable in the $PATH.
+#
+# which('ruby') #=> /usr/bin/ruby
+def which cmd
+ exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
+ ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
+ exts.each { |ext|
+ exe = "#{path}/#{cmd}#{ext}"
+ return exe if File.executable? exe
+ }
end
+ return nil
end

0 comments on commit 252b3cc

Please sign in to comment.