Stephen Celis

Bashfully Yours, Gem Shortcuts 12 Jun

To gain quick bash access to your rdocs, add these lines to your ~/.bash_profile:

export GEMDIR=`gem env gemdir`

gemdoc() {
  open $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

Let’s try it out…

$ source ~/.bash_profile
$ gemdoc hpricot

Hpricot

It will automatically open the latest version, but you can specify any version you’d like, and tab completion simplifies the task:

$ gemdoc P→arseTree-2.→→
ParseTree-2.1.1/  ParseTree-2.2.0/

Great. All bases covered. Modify slightly if you want to open gems in your favorite $EDITOR. Replace open with your favorite website-opening command if you’re not on OS X.

(Hat tip to Mislav for the dotfile inspiration.)