Skip to content

Instantly share code, notes, and snippets.

@LTe
Created August 23, 2013 09:10
Show Gist options
  • Save LTe/6317158 to your computer and use it in GitHub Desktop.
Save LTe/6317158 to your computer and use it in GitHub Desktop.
set tags=./tags;$HOME
#!/usr/bin/env ruby
require 'rubygems'
require 'bundler'
# Exit if there is no Bundler
unless defined?(Bundler)
puts 'No Bundler found. Please run gem install bundler.'
exit
end
# Rtags processor
class Rtags
attr_reader :full_name, :help
def initialize
@options = {}
ARGV.each_with_index { |v,idx| @options[ARGV[idx*2]] = ARGV[idx*2+1] }
@full_name = File.join(options['-f'] || './tags')
@help =<<-TEXT
Generates ctags tagfile with included gems from bundle.
Options:
-h - shows this help
-f - tagfile name (default './tags')
TEXT
end
def options
@options
end
def has_help_key?
options.has_key?('-h')
end
def generate_ctags
if File.exists?("./Gemfile")
create_project_ctags(full_name)
create_gems_ctags(full_name)
puts "\n", 'Completed!'
else
puts 'Run script in folder with Gemfile.'
exit
end
end
private
def create_project_ctags(full_name)
puts 'Creating ctags'
ENV["BUNDLE_GEMFILE"] = File.join(ENV["PWD"], "Gemfile")
`rm #{full_name}` if File.exists?(full_name)
`ctags -f #{full_name} -R .`
end
def create_gems_ctags(full_name)
Bundler.load.specs.each do |s|
`ctags -a -f #{full_name} -R #{s.full_gem_path}`
print "."
end
end
end
# Executing script
r = Rtags.new
if r.has_help_key?
puts r.help
exit
else
r.generate_ctags
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment