Saturday, May 5, 2012

I've been wanting this for years

In tcsh (since that's what I use, so if you use bash, you'll have to write this yourself):

alias postcmd 'if ( "\!#:0" =~ "http*" ) wget \!#:0'
http://www.littlepuppy.org/wp-content/uploads/2011/10/puppies-2.jpg



--2012-05-05 12:12:06--  http://www.littlepuppy.org/wp-content/uploads/2011/10/puppies-2.jpg
Resolving www.littlepuppy.org (www.littlepuppy.org)... 66.147.244.53
Connecting to www.littlepuppy.org (www.littlepuppy.org)|66.147.244.53|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 28027 (27K) [image/jpeg]
Saving to: `puppies-2.jpg'


100%[======================================>] 28,027      64.5K/s   in 0.4s    


2012-05-05 12:12:07 (64.5 KB/s) - `puppies-2.jpg' saved [28027/28027]


http://www.littlepuppy.org/wp-content/uploads/2011/10/puppies-2.jpg: Command not found.
Exit 1

So, with this postcmd defined, anytime you paste an http based url to the command line, and execute it like a command, it runs wget to fetch that url for you.


No comments:

Post a Comment