shell

curl is awesome; Typepad is not

Tom Lee's picture

Sometimes I wonder why I ever bothered to compile wget for OS X. I keep finding clever new things that curl can do — even some that make me wonder why I bother with Perl and Ruby's Mechanize module/gem.

For instance: today I found myself needing to export a friend's Typepad blog. He's got a lot of content, and I wanted to pull it down on a speedy connection and then gzip it before pulling it onto my laptop over my sluggish DSL (Typepad unhelpfully delivers its exported content in an uncompressed non-ML format).

Typepad provides a URL for the export, but it only works when you've authenticated through their website. Curl makes working around this pretty simple, though, as I found out from this Ask Metafilter thread. Here's how it works:

curl -k -d "__mode=redir&next=http://www.typepad.com/t/app&username=user%27s+name&password=their%20password" -c cookie.txt https://www.typepad.com/t/app

You simply use -k to turn off SSL requirements, -d to pass a series of key/value form pairs (properly url-encoded) to the URL to which the form posts, and -c to output the returned cookie to a file.

Then you pass in the session-containing cookie file, allowing you to stay authenticated on subsequent requests:

curl -b cookie.txt -o complete-export.txt "http://www.typepad.com/t/app/weblog/post?__mode=export&blog_id=YOUR_BLOG_ID"

Naturally, you'll want to replace the URL in that last request with the one corresponding to your own export URL.

It all worked perfectly — well, up until the point at which I discovered that Typepad exports seem to inevitably fail once they top 100 megs. Seriously guys: file compression. Try it, you'll like it.

first post: how the shell made me go !h:7 !!

Ethan's picture

Hi I'm Ethan, the new guy. This is my first post, but beyond that brief bio and the unequivocal denial of any claims that I don't change my shirt on a daily basis, this post isn't going to be about me.

It's going to be about the totally off the hook tricks I leaned about the "previous command" shell shortcuts I learned today from this post and how they totally rocked my world a second ago.

So here's the situation: I downloaded a file and couldn't remember whether it was a zip or a tarball, so I ran this command:

tar -xzf ~/downloads/google-sitemap-generator.3.0b7.zip

Why did I try to unzip a tarball, you ask? Because I'm lazy, and when autocomplete says "press enter", I ask "how fast"? Needless to say, the result was some mumbo-jumbo that I'm sure must have had ample amounts of bit-level impatience buried somewhere underneath it.

Remembering the tricks from that post I tried this:

unzip !^

I was thinking that maybe the first argument (referenced by !^) would be recognized as the argument after the flags. But no go, it resolved to unzip -xzf

Now I had a bit of a dilemma: I couldn't use any more of the cool tricks because they all referred to the command prior to the last...unless. What if all the argument referencing commands could be prefixed with a pattern!?! Sure enough, this gem worked like a charm...gem...:

unzip !tar:2

Which basically reads unzip {the second argument of the last command matching the glob-string 'tar'}

To my total, complete astonishment it actually worked. Brilliant.