photo
Jordan Sissel
geek

Wed, 28 Mar 2007

Shortcuts in your shell

I always run across commands I want to run more than once, but don't necessarily merit an alias in my zshrc file. For these commands, I abuse environment variables and use them as prefixes.

For instance, I have one command that runs mplayer in a loop, in case the connection drops:

while true; do mplayer -cache 48 -prefer-ipv4 http://foo.com/streamthing; done
Normally, I might use !while to re-invoke this command. However, I have lots of oneliners in my shell history that start with while. So, let's hack around it:
MPLAYER= while true; do mplayer -cache 48 -prefer-ipv4 http://foo.com/streamthing; done
This will set the environment variable 'MPLAYER' to an empty string and pass it to the while subshell (and thus mplayer), but since MPLAYER isn't used as an environment variable in mplayer, we won't break anything.

Now, any time I want to rerun this specific command, I can just do !MPLAYER and we're all set. Doing this is *extremely* useful and allows you to define alias-like procedures in real-time, assuming you have a persistent shell history. If you don't have a persistent shell history, set it up, as it's useful for more things than the above hack.

Comments: 0 (view comments)
Tags: , ,
Permalink: /geekery/shell-shortcut-hacks
posted at: 14:14

Search this site

Navigation

Metadata

Home About Resume My Code

Articles

ARP Security Dynamic DNS with DHCP OpenLDAP+Kerberos+SASL PPP over SSH SSH Security: /bin/false Week of Unix Tools Work Efficiency

Projects

fex firefox tabsearch firefox urledit grok keynav liboverride newpsm (FreeBSD) nis2ldap pam_captcha poor man's backup Solaris audio utility xboxproxy xdotool xmlpresenter xpathtool misc scripts

Presentations

Yahoo! Hack Day '06 Unix Essentials Vi/Vim Essentials

Tag Cloud

Calendar

< March 2007 >
SuMoTuWeThFrSa
     1 2 3
4 5 6 7 8 910
11121314151617
18192021222324
25262728293031

Friends

BarCamp Kent Brewster Tantek Çelik John Resig Wesley Shields Tyler Shields

Technorati