Creating Smart Keywords in Elinks

October 3, 2007 – 11:07 am

I have recently ramped up my usage of the ELinks text browser. I have been working on our servers a bit, and I often do not have X windows enabled at the time. ELinks is a great way to check my Gmail account and goof off on the web when I’m waiting for something to finish. My favorite part about using ELinks is how quickly pages load. That’s the obvious beauty of text web browsing.

One of the biggest annoyances I had with ELinks was my inability to maneuver around with just a few keystrokes. It seemed like I often had to pound on the arrow keys a dozen times to get where I wanted, or I had to type out whole URLs in some cases. The bookmarks eased that burden a bit, especially given that the URL for the plain HTML version of GMail is a bit cumbersome. But navigating through bookmarks can get old. I really wanted something like the Smart Keyword system in Firefox.

I finally figured out a great solution for me personally. I compiled a copy of ELinks that lives in my home directory with Ruby support. After downloading the tarball from the Elinks download site and unpacking it, a simple


./configure --prefix=$HOME --enable-256-colors --with-ruby ; make ; make install

gave me an elinks executable in my $HOME/bin directory. I of course had to have the relevant Ruby packages installed for this to work. Now that I have Ruby support, I can create the file $HOME/.elinks/hooks.rb. Here’s what the contents of that file look like:


def ELinks::goto_url_hook(url, current_url)
if (url[0,4] == "fin\ ")
symbol = url[4,url.length]
url = "http://finance.google.com/finance?q="
url.concat(symbol)
elsif (url[0,5] == "wiki\ ")
symbol = url[5,url.length]
url = "http://en.wikipedia.org/wiki/"
url.concat(symbol)
elsif (url == "gm")
url = "http://gmail.google.com/gmail?ui=html&zy=n"
end
end

What does this code mean? Well, the first part of the if statement says that if I enter fin ko in the ELinks’ URL field, I actually want to go to the Google Finance page for Coca-Cola. This works exactly the same way my Smart Keyword does in Firefox. The next block of code says that if I enter wiki Michael_Jackson in the URL field, I want to view the Wikipedia page on Michael Jackson. These two shortcuts save me from navigating first to Google Finance or Wikipedia and then searching for the specific page I want. It saves quite a bit of time, especially when using a text-based web browser like ELinks.

The last bit of code in hooks.rb says that if I enter gm in the URL field, I want to go to GMail. This is even more convenient than the bookmark system. For that system, I have to get to the bookmark manager and then use the arrow keys to scroll up or down to the links I want. With this hook, I can go immediately to the plain HTML version of GMail without having to type the address manually or navigate through my bookmarks to get there.

Post a Comment