Skip to content

Instantly share code, notes, and snippets.

@heycarsten
Created August 21, 2008 14:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heycarsten/6570 to your computer and use it in GitHub Desktop.
Save heycarsten/6570 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby -w
require File.join(ENV['TM_SUPPORT_PATH'], '/lib/textmate')
PROJECT_DIR = ENV['TM_PROJECT_DIRECTORY']
METHOD_NAME = ENV['TM_CURRENT_WORD'] || ENV['TM_CURRENT_SELECTION']
def blank?(string)
string.nil? || string.strip.eql?('')
end
def helpers_dir
File.join(PROJECT_DIR, '/app/helpers/*')
end
def grep_and_go_to!
method_name = Regexp.escape(METHOD_NAME)
grep = `grep -rnE "def #{method_name}([\( ]{1}|$)" #{helpers_dir}`
filepath, line = grep.match(/^.+:[\d]+/).to_s.strip.split(':')
if filepath && line
TextMate.go_to(:file => filepath, :line => line)
else
puts 'Could not find a matching Helper file'
end
end
if blank?(PROJECT_DIR)
puts 'Go To Helper Method only works in a project!'
elsif blank?(METHOD_NAME)
puts 'Place the cursor over the name of a Helper method'
else
grep_and_go_to!
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment