Skip to content

Instantly share code, notes, and snippets.

@jgandt
Forked from andyl/ctags_vim_paths_gemfile.rb
Created January 31, 2012 15:26
Show Gist options
  • Save jgandt/1711064 to your computer and use it in GitHub Desktop.
Save jgandt/1711064 to your computer and use it in GitHub Desktop.
Generates Ctags and Vim Paths from Gemfile.lock
#!/usr/bin/ruby
require 'rubygems'
require 'bundler'
=begin
This script was written to incorporate Bundler and Gemfile.lock into
Vim's tag and file-finding tools.
=end
# This code generates ctags. If a Gemfile.lock is found
# in the current directory, tags will be generated for
# every gem referenced in the Gemfile.
bundler_paths = []
if File.exist?('Gemfile.lock')
lockfile_contents = Bundler.read_file('Gemfile.lock')
lockfile = Bundler::LockfileParser.new(lockfile_contents)
bundler_paths = lockfile.specs.map do |spec|
spec.__materialize__
spec.full_gem_path
end
end
opts = "--extra=+f -R"
exclude_dirs = "--exclude=.git --exclude=log --exclude=.svn"
ctag_paths = "* #{bundler_paths.map {|x| x + '/*'}.join(' ')}"
command = "ctags #{opts} #{exclude_dirs} #{ctag_paths} 2> /dev/null"
puts "Processing ctags..."
system command
puts "Finished generating tags file."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment