Published on March 13, 2012 by Jesse Storimer
If I'm not in the terminal then I'm not doing real work.
Recently I had to refer to my book while I was working on a project. I work in a full-screen terminal and don't like to leave it. The world outside my terminal is filled with distractions, bright colours, and menus. My textual environment is where my real work happens.
So to consult my book I opened the PDF version and kept switching context back and forth between the PDF and the terminal. Have you tried copying and pasting code from a PDF lately? Not perfect.
I had the same experience when I was reading Objects on Rails. As I was reading the text I wanted to follow along with the code examples. I was annoyed with switching back and forth between my graphical reader and my programming environment.
A few days later I read this. It's a free eBook about Linux, available in several formats including TXT. Brilliant!
This made perfect sense to me. As a programmer I'm used to working in the terminal. If I'm going to be referring to a technical book while I'm working then, of course, I want to be able to read the book from my terminal.
Back to my original issue: I converted both my book and my copy of Objects on Rails to TXT files1 and set this up:
$ alias wwup='less /path/to/workingwithunixprocesses.txt' $ alias oor='less different//path/to/objectsonrails.txt'
Now when I'm working in a terminal I can just open a new session and type
oor to read the books.
The best part about this is that the book is now in the realm of the powerful text processing tools offered in the terminal. There's simple things like piping the book text into grep(1) to search for something, but the most useful tool is certainly less(1). Notice that I loaded the text with less(1) as part of the alias I created.
less(1) is so useful for this kind of stuff. Vim users will be right at home with its commands. You can scroll the text up and down line-by-line using
k respectively. Use
Ctrl-u to scroll the text up and down page-by-page. Besides the basic movement commands the most useful feature for reading is incremental search. Press
/ and start typing to begin a search. Any matches in the text will be highlighted, at this point you can use
n to see the next match and
N to see the previous match.
It's also really easy to play with some code while keeping the text open, the exact thing I wanted to do when reading through Objects on Rails. You can shell out from less(1) by prefixing a command with a
!. So you can use
!irb to open an irb session right from less(1). Copy and paste code that you're reading right into the irb session for easy tinkering. If I'm working on something more incremental I just split my shell horizontally, reading the book on one side and coding on the other side.
I think I'll definitely start doing this for programming books that I'm reading. Especially for ones that are useful to keep around as references.
Working With Unix Processes now ships with a TXT version alongside the other formats. The book will be available at 40% off until this Friday because I think this is fun and I want you to have it.