Git-Style Automatic Paging in Ruby
I was using Chris Wanstrath’s cheat the other day, seeing if there were any cool git features I was missing out on (did you know you can color the output?). If you haven’t come across it yet, cheat is a nice little Ruby utility that displays “cheat sheets”— user-generated pages of text that serve as miniature reference manuals.
Unfortunately, some of these cheat sheets can get pretty long.
The git one is 228 lines.
Some of the text went off the top of my terminal.
I sighed and typed in cheat git | less,
thinking once again how nice it would be if more programs followed git’s example
and automatically paged their output.
Although git’s not usually held up as a paragon of usability1,
there are a few places where it shines.
My favorite is how it’ll run less on its output
when the output is too big to fit on my terminal screen.
Then I can easily scroll and search through the text.
Since I had a bit of time with nothing urgent to do, I decided to take a crack at making cheat page like git. Two and a half hours later, after digging through git’s source, getting help from the good folks in #git and #ruby-lang on Freenode, and receiving tons of bug fixes from Kevin Ballard, I got it to work.
About Me
Feed
February 2008
6 Comments
More

