LWN.net Logo

Shell programming

Shell programming

Posted Dec 2, 2012 18:44 UTC (Sun) by bokr (subscriber, #58369)
In reply to: Shell programming by man_ls
Parent article: Quotes of the week

#!/usr/bin/bash
kwds="$(echo $@|tr ' ' '+')"
ffarg="http://en.wikipedia.org/wiki/Special:Search?search=$kwds"
firefox $ffarg &

I like being able to make things easy for myself ;-)

I prefer typing "wkf something" over Alt-Tabbing to firefox (if it's running or grabbing the mouse and clicking a sys tray icon if it's not), and then mousing down a menu to select wikipedia (if it's set to google) and then clicking focus to the search slot if necessary, and typing in "something" there.

It's so easy to make a little utility command. If I look up something on on the net more than a few times, like as not I'll put a little script for it in my ~/bin (which is on my $PATH), e.g. areagrep to look up areacodes, ccgrep to look up country codes, airpgrep to look up airports and their codes, etc. (most of these work by a 2-line bash prefix calling grep on the rest of the file as a heredoc, or even grepping $0 and exiting, where the heredoc is made by pasting a table copied from some public web page e.g. areacodes from wikipedia for areagrep. They nicely made it easy to search for specific areacodes by suffixing a colon to area code in the text. So

[18:48 ~/bin]$ areagrep 206:
206: State of Washington (Seattle, all of Bainbridge, Mercer, and Vashon islands, Burien, Des Moines, Lake Forest Park, Normandy Park, Sea-Tac, Shoreline, Tukwila, and some small unincorporated areas adjacent to these. Also, parts of Woodway and Edmonds)
[18:48 ~/bin]$ areagrep 212:
212: New York City (Manhattan except for Marble Hill)

Also it's nice to be able to get any result that comes from these little trivial utilities right into vim, just typing in vim, e.g., ":r!areagrep 212:"

I have a collection of throwntogether stuff, which I think would grow even faster if command line access to clipboard and running programs were more standard and less arcane. E.g., for x clipboard stuff I had to get xclip and compile it, and to get text dynamically from the web may involve e.g. getting wget to impersonate firefox and filtering through an adhoc python script.

But bottom line:
I think there's a bright future for command line input to computers ;-)


(Log in to post comments)

Shell programming

Posted Dec 2, 2012 19:37 UTC (Sun) by boudewijn (subscriber, #14185) [Link]

Nice script... But I prefer to press alt-f2, and then type "wp:maillol" if I need to get the wikipedia article for that lemma. Or "qt:qstring" if I've forgotten once again what the correct way of converting an integer to a string is. Or "dict:espieglerie" for definitions of the word I always assumed meant "mirror" or "ggi:maillol" for images of sculptures by the master. In fact, I'm so used to it that I never keep a browser window open, at all.

Shell programming

Posted Dec 10, 2012 0:20 UTC (Mon) by Baylink (subscriber, #755) [Link]

Sure. But his approach is much more portable across workstation OS distributions than yours is. :-)

Shell programming

Posted Dec 18, 2012 12:35 UTC (Tue) by wookey (subscriber, #5501) [Link]

I tried that and a little window opened to type in, but hitting return said:
Failed to open URI "wp:maillol"

I'm using XFCE. What were you using?

Shell programming

Posted Dec 18, 2012 13:00 UTC (Tue) by boudewijn (subscriber, #14185) [Link]

KDE of course. KDE's krunner is amazingly powerful and useful.

Copyright © 2013, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds