Skip to content

Instantly share code, notes, and snippets.

@thata
Created February 18, 2009 02:24
Show Gist options
  • Save thata/66144 to your computer and use it in GitHub Desktop.
Save thata/66144 to your computer and use it in GitHub Desktop.
grep-gems
#! /bin/sh
# grep-gems
#
# (1) grep rubygems sources.
# > grep-gems "def select_tag"
#
# (2) open source.
# > grep-gems "def select_tag"
# 1 /usr/lib/ruby/gems/1.8/gems/foo/a.rb
# 2 /usr/lib/ruby/gems/1.8/gems/foo/b.rb
# 3 /usr/lib/ruby/gems/1.8/gems/foo/c.rb
# > grep-gems "def select_tag" 3 # open foo/c.rb
if [ $# -eq 2 ]
then
vi `cat /tmp/grep-gems-result | grep -e "^[ ]*${2}[^0-9]" | awk '{ print $2 }' | tr -d ':'`
else
rm /tmp/grep-gems-temp &> /dev/null
for i in `/usr/bin/env ruby -rubygems -e 'puts Gem.path'`
do
if [ -e "${i}/gems" ]
then
find "${i}/gems" -nowarn -type f >> /tmp/grep-gems-temp
fi
done
cat /tmp/grep-gems-temp | xargs grep "$1" -s | cat -n > /tmp/grep-gems-result
cat /tmp/grep-gems-result
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment