Skip to content

Instantly share code, notes, and snippets.

@placek
Last active September 17, 2015 08:50
Show Gist options
  • Save placek/81435d565d528bcc25b6 to your computer and use it in GitHub Desktop.
Save placek/81435d565d528bcc25b6 to your computer and use it in GitHub Desktop.
ctags generator for ruby project using bundle
#!/usr/bin/env ruby
require 'bundler'
class CTagsService
def call
trap_int_signal
system(command)
system(['mv ', tmpfile, ' .git/tags'].join)
end
private
def tmpfile
@tmpfile ||= ['.git/tags.', Process.pid].join
end
def directories
Bundler.load.specs.map(&:full_gem_path) << Dir.pwd
end
def trap_int_signal
Signal.trap('INT') do
remove_tmpfile
puts 'aborted, exiting...'
exit
end
end
def remove_tempfile
system(['rm -f ', tmpfile].join)
end
def command
[].tap do |command|
command << 'ctags --tag-relative -Rf'
command << tmpfile
command << '--exclude=.git --languages=-javascript,sql'
command += directories
command << '> /dev/null 2>&1'
end.join(' ')
end
end
CTagService.new.call if __FILE__ == $0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment