FastRI set up on my Mac

RI is a bit like the Unix man command for Ruby, giving command line access to API docs. Trouble is that It can be slow, bordering on unusable. FastRi is miles faster. You do need the fastri-server running though. Here’s my setup.
First I installed FastRi. You can do a gem install, but running from a tarball install is faster, so I downloaded fast-ri.0.3.1.tar.gz from the Rubyforge page and untarred. From that directory I ran
$ sudo ruby setup.rb all --bindir=/usr/bin/
Then I checked it worked by running fastri-server -b to build the index, then fastri-server to run the server. In another terminal I type fri Array, and the RI documentation for Array appeared at greased-ferret speeds.
Next I want the server to run in the background on startup, so first I killed the current fastri-server and created a launchd plist configuration, /Library/LaunchDaemons/fastri-server.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>fastri-server</string>
<key>KeepAlive</key>
<true/>
<key>ProgramArguments</key>
<array>
<string>/usr/bin/fastri-server</string>
</array>
</dict>
</plist>
Next I kicked the Daemon off
$ sudo launchctl load /Library/LaunchDaemons/fastri-server.plist
Then I confirmed that fri Array works again, this time from the fastri-server daemon.
One thing still irritating me was that an RI document of any size scrolls off the top of my terminal window and I need to scroll up to read it. I added a little shell script somewhere on the path, fastri-less.sh
#!/usr/bin/env sh
/usr/bin/fri -f plain $1 | less
Next I aliased fri, and ri to use the new script. In ~/.profile
alias ri='fastri-less.sh'
alias fri='fastri-less.sh'
That's about it. Toying with setting up a job to reindex fastri every so-often. I'm not sure it's necessary; I'll see.
Labels: ruby fastri
