Terminal

A command line ebook reader

I was casting around for a replacement for the excellent Tofu screen text reader for Mac, due to some encoding issues. Always wont to explore the command-line options, I turned first to the ubiquitous less pager, available on pretty much every unix-alike system out there.

The only real drawback to less is its apparent inability to wrap long lines at spaces rather than chopping words in the middle and sans hyphenation. This isn’t a problem on hard-return files like a Project Gutenberg ebook, but makes for difficult reading otherwise. (The opposite is the case for Tofu, which requires a bit of manual column widening to compensate for the hard returns.)

Doing a bit of poking around, I re-discovered the also-ubiquitous fmt command, which does word wrapping to a fare-thee-well, though doesn’t do paging.

Combining the two commands gives the best of both in classic Unix fashion:

fmt 1911EthanFrome.txt | less

You can also use options to enhance the experience. less -m will give you a prompt showing how far along you are in the file; see man less for others.

The pager recognizes vim movement keys, which I love. Plus you can hit the v key at any time to drop into vim, edit the file, and then return to less. Spiffy.

Of course, you could just use vim (or your favorite text editor), but I like the simplicity without the overhead. Unlike other options, less doesn’t read the entire file into memory before displaying it, a definite advantage on big documents.

Another Tip: If you’re in a Mac Terminal window, right click on a word or phrase to search for it in Google or Dictionary.

Bonus tangential tip: if you don’t care about downloading the text files but want to stick to reading Project Gutenberg files in the terminal, why not use lynx or ELinks?

screenshot of terminal window showing lynx web browser viewing the Edith Wharton novel Ethan Frome on Project Gutenberg

Command line tea timer for Mac

Cuppa is a spiffy tea timer program for Mac (if only for its sound effects ;), itself inspired by The Tea Cooker from Linux. However, there’s an easy way to create a de facto tea timer, or run any kind of countdown, via the Terminal.

The sleep command allows you to run other commands or programs with a delay. So, for example, you could enter,

sleep 20; ps

which will pause for 20 seconds, then run ps to show your active tasks.

To keep you from having to stare at the Terminal window waiting for your tea countdown to finish, we’ll make use of the say command, which taps into your Mac’s built-in Text-to-Speech ability. (See System Preferences > Speech.)

So, assuming you want your Earl Grey to steep for four minutes, you could use something like this:

sleep 240; say "Your Tea, Earl Grey, Hot, has completed brewing."

Or for your Green Tea:

sleep 60; say "Green Tea processing complete."

Enjoy!

Lynx package for Mac OS X

Via osxgnu.org, a Universal Terminal and Finder-clickable Lynx package (self-contained), currently at version 2.8.6u.

links for 2007-10-24

Terminal.app with tabs

Browsing through the features and technology of the fast-approaching Leopard, I happened across the UNIX page and a mention of “Terminal 2,” an updated version of the bundled term application. Here’s the spiel:

The Terminal application in Leopard takes advantage of the operating system’s native text and graphics capabilities, using Input Manager and CoreText to fully support non-English languages. The updated layout engine provides very fast rendering of ASCII, ISO, and Unicode text, and a new user interface gives users around the world the ability to harness the power of UNIX. A simplified inspector and integrated settings pane make it easy to change the look and feel of Terminal.

New user interface, eh?

Now, I spend a lot of time in the CLI environment, although it’s currently shifted over to iTerm due in large part to its tabbed windows. Lo and behold, check out the top of Terminal 2’s window:

terminal 2 screenshot showing tabs

Syndicate content