brhfl.com

ep

This is an old post from an old blog; assets may be missing, links may be broken, and my opinions may differ considerably by this point…

I spend a good deal of time inside a terminal. Text-based apps are powerful, when you know what you're doing, and fast (also when you know what you're doing, I suppose). If an equivalent Cocoa or X11 GUI tool offers me little advantage, I'm probably going to stick to either a CLI- or TUI-based piece of software. One of the more important, taken-for-granted pieces of the command line environment is that of the pager. Typically, one would use something like more or less for their pager. For a while, I used w3m as my pager, as well as my text-based web browser. Then Snow Leopard came out, and everything from MacPorts got totally jacked up and left much of my system jacked up as well. Parts of it I've fixed, other parts I've been lazy about. For that reason, or perhaps not, I have transitioned to ELinks as my text-based web browser. Today, after recent discussions with a friend regarding w3m and ELinks, I had a thought - why not use ELinks as my pager as well?

My reasoning is pretty simple - ELinks is quick enough to work suitably as a pager, and it has scrollwheel support! This is really quite nice, because as much as I love the keyboard, momentum scrolling with a Magic Mouse is a game-changer. So those are the 'whys,' and a quick run of ls | elinks does plenty to demonstrate the 'why nots':

elinks, by default, throws up a mimetype request

So, this isn't desirable in a pager - responding to a modal dialog before seeing the output. A pager should show the text it's supposed to show with no further prompting, and ideally no delay whatsoever. It should be a fairly transparent piece of the command line, really. This is easy to suppress - just run elinks -default-mime-type "text/plaintext" and you're good to go. But then another ugly demon roars its head:

confirm quit? no thank you!

Pressing q is a normal ELinks quit - throwing up a confirmation box. Again, not desirable in a pager. Shiftq quits without confirmation, but in my mind, a pager quits with a bare q. This can't be set with command line arguments, so the process begins…

Fortunately, ELinks lets you choose a custom configuration file by means of the -config-file argument. So step one is to make a custom config file in ~/.elinks called pager.conf. I just copied my elinks.conf to pager.conf and added from there. Additions are as follows:

#bind q to quit without confirmation
 bind "main" "q" = "really-quit"
#set a default mimetype (plaintext)
 set mime.default_type = "text/plaintext"
#get rid of useless bottom status bar (see above)
 set ui.show_status_bar = 0

So that was step one - making a more pager-esque conf file for ELinks to use. Step two is simply making it so that I don't have to type ls | elinks -config-file pager.conf all the time. I use (and love) fish as my shell, which can use traditional aliases, but prefers its own built in function system. So, added to my .fish file is…

function ep -d "Use ELinks as pager"
  elinks -config-file pager.conf $argv
end

…which allows me to use ep (ELinks pager) as an alias to running elinks with the pager.conf file loaded. Other shells (and, technically, fish as well) can achieve this with alias ep=elinks -config-file pager.conf. (I believe. Correct me if I'm wrong, it's been a while.) And with that, you have ls | ep for a nice, scroll-wheel-friendly pager. One unfortunate reality is that behavior is more like more than like less - the whole stdin needs to be read before the display is rendered. For very large listings, this is… unpleasant at best.


•