Open rdocs for installed gems

By way of Ruby Inside, this site has a .bash(rc|_profile) function/completion to open rdocs for installed gems on your machine.

I changed it slightly so that it would just open in a new tab in firefox.

Put this in your .bash(rc|_profile):

export GEMDIR=`gem env gemdir`

gemdoc() {
firefox -new-tab $GEMDIR/doc/`$(which ls) $GEMDIR/doc | grep $1 | sort | tail -1`/rdoc/index.html
}

_gemdocomplete() {
COMPREPLY=($(compgen -W '$(`which ls` $GEMDIR/doc)' -- ${COMP_WORDS[COMP_CWORD]}))
return 0
}

complete -o default -o nospace -F _gemdocomplete gemdoc

Then source that file, and try it out.


$ gemdoc acts[tab][tab]

Will show you all the gems you have that start with acts. Then complete the whole thing and it will open the rdoc in a new tab in your already running instance of Firefox.

About Nathan Powell

I am a middle aged technologist freak-ball.
This entry was posted in programming. Bookmark the permalink.

Comments are closed.