Edit in Textmate on Leopard

Thursday, November 15

After upgrading to Leopard, I noticed that the ‘Edit in TextMate’ command stopped working. This is a neat little hack that allows you to edit the contents of just about any Cocoa text control within TextMate. At first I was like, meh, no big deal. But after living without it for a few weeks, I realized just how useful it is.

A bit of googling revealed the cause: the rules governing Input Managers have changed in Leopard. Fortunately, TextMate creator Allan Odgaard has a detailed post on how to fix this.

http://blog.macromates.com/2007/inputmanagers-on-leopard

Related: SIMBL Hacks

Also affected by the change to Input Managers were some of my SIMBL hacks, specifically, the hack that I used to customize the default colours of Terminal.app: Mike Solomon’s TerminalColors. Being designed for Tiger’s Terminal.app, this wasn’t working for the new Leopard version.

Ciaran Walsh has re-hacked the hack, and I’m happy to report that I can finally read blue on a black background again. Thanks Ciaran!

http://ciaranwal.sh/2007/11/01/customising-colours-in-leopard-terminal

BTW, the new Terminal.app is completely awesome. Finally, a fast, tabbed terminal for OS X.

Links for today: 1

Tuesday, September 04

And now for something new. Links for today. Whatever. It’s new to me.

  • Has finder: a new ActiveRecord extension that makes it easier than ever to create custom find and count queries. Looks better than both of scope-out and scoped-proxy.
  • Zooom: window stuff for OS X. Done right.
  • Webistrano: a web front-end for Capistrano.
  • Seesaw: high-availability Mongrel Packs.
  • Sphincter: ActiveRecord extension for full-text searching with Sphinx.

Two Things I didn't know about TextMate

Friday, January 20

The TextMate Manual was recently published and I made some time today to go through it. I always seem to work with an editor for far too long before I realize there’s some handy shortcut I’ve been ignorant of. Anyways, an editor like TextMate is full of these hidden gems—clever macros and commands that make life easier. Here are a couple of things I didn’t know.

CMD-T: Go to File

Until this moment, I had no idea the ‘Go to File’ window existed, let alone its CMD-T shortcut. I hate taking my hands off the keyboard to click on files in the project drawer, so the ‘Go to File’ command makes my day. It opens a window containing a flat list of all the files in your project, with a live, abbreviation-enabled search.

[This] window lists all text files in the project sorted after last use, which means pressing return will open (or go to) the last file you worked on. So using it this way makes for easy last-recently-used switching.

From 2.3 Moving Between Files

CMD-Return: Save some keystrokes

You know how when you type an auto-paried character, like a quote, or a brace, your caret ends up in between the pair? Well, this is generally useful, but really sucks when you’re at the end of a line because you have to move all the way to the end before making a carriage return. You can imagine my excitement when I learned about CMD-Return. CMD-Return will move to the end of the line and insert a newline for you. How great is that?

From 4.1 Auto-Paired Characters

Comfortable, Color CLI

Friday, January 13

Torn as I now am between my iMac and my laptop (Ubuntu linux), I invariably find myself using both: OS X at the desk, Ubuntu on the couch. My brief tenure in linuxland taught me to embrace the CLI (Command Line Interface), and upon returning to mactopia, I find I use the CLI almost exclusively. (That and VIM. I decided early on that rather than waste time learning yet another GUI editor, I’d take the opportunity to learn VIM and promptly fell in love. I’m typing this in VIM right now, even as my TextMate icon stares up at me from the dock.) For me, Linux and Darwin are sufficiently similar that I’m at home on either and I’ve come to respect their subtle differences.

That said, one thing I really liked about the default bash terminal in Ubuntu was its color, so I sought to bring this feature over to my OS X Terminal. Using ls with color makes things faster—colors can tell you about files in ways that ls -F never could. To enable this in OS X (bash), you’ll need to add some options to your .profile:

export CLICOLOR=1
export TERM=xterm-color

The first line turns on color, and the second ensures that your terminal is declared as color capable. While this will work as advertised, it won’t necessarily look very good if you use a dark background. By default, directories are listed in blue, and while this looks good in Ubuntu it’s just too dark on the Mac. For those of us who rock a black background, you might want to change the ls colors.

export LSCOLORS=gxfxcxdxbxegedabagacad  # cyan directories

In the above example, I’m using cyan for directories; this is a fair compromise and looks nice in both OS X and Ubuntu. If you want to know about each of the color codes above, they’re listed in the ls manual (man ls).

For the complete linux effect on OS X, a green prompt will also be necessary. Without getting in the sordid details of customizing your prompt (it’s a long and arduous tale that I’ll save for another article), I offer this:

export PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;36m\]\w\[\033[00m\]\$ '

When we put it all together, we get a comfortable and portable CLI that looks quite nice, no matter where you’re logging in from.

# colors
export CLICOLOR=1
export TERM=xterm-color
export LSCOLORS=gxgxcxdxbxegedabagacad  # cyan directories
export PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;36m\]\w\[\033[00m\]\$ '

GPG Quickstart Guide

Sunday, October 23

This is a quickstart, so let’s not waste any time. The first thing your going to need is a GPG Key, so fire up the terminal and from the command line, type:

$ gpg --gen-key

This will launch the GPG key-generation program. First you’ll be asked to select what kind of key you want: (1) DSA and Elgamal (default), (2) DSA (sign only), (5) RSA (sign only). If you want to sign and encrypt messages, DSA and Elgamal is what you want and is the default, so we’ll use that.

Next you’ll be asked to choose a keysize. A large keysize is more secure than a small one, but also takes longer for your computer to encrypt/decrypt data. The default value of 1024 is adequate, so we’ll use that. If you’re really paranoid, you can use 2048, which is currently gpg’s maximum.

You’ll then be asked to set an expiry date for your key. While expiry dates can be used for stronger security, you probably want your key to be valid indefinitely. Choose 0 (the default) to create a key that never expires and confirm your selection.

You need a user ID to identify your key. You’ll be asked for your Real Name, Comment and Email Address which will result in a user ID in this form: “Real Name (comment) <email@example.com>”. Go ahead an type in your user ID details and confirm your entry.

Finally you have to enter a passphrase. A passphrase is like a password, but is longer, can contain spaces, and is supposed to be impossible to guess. Think of a passphrase as a super-password. Use a long sentence, or a line from one of your favorite songs, spaces and punctuation included. Oh, and if you ever forget your passphrase, there is NO way to get it back.

All done? Congratulations! You now have a public and secret key in your keyring. To see all your keys, use the list-keys command:

$ gpg --list-keys

Create a revocation certificate

If you ever need to revoke this key (because, say, you forgot your long and difficult-to-guess passphrase), it helps to have a revocation certificate prepared. Right after creating a key is a good time to prepare a revocation, so let’s do it now.

$ gpg --gen-revoke packagethief > ~/revcert.asc

You’ll have to answer a few questions (the default answers are fine) and enter the passphrase you chose for your key. The above command will create your revocation certificate in the file revcert.asc. Now, keep in mind that if someone gets a hold of this revcert, they’ll be able to revoke your key and render all your encrypted messages unreadable. You probably don’t want this, so it’s a good idea to hide this somewhere OFF your computer. You could put it on another volume, save it to a disk and keep in somewhere safe, or just print it and keep it locked away in your filing cabinet. At the very least, you want to make sure that nobody except you can read it, so let’s change the permissions:

$ chmod u-w,go-r ~/revcert.asc
$ ls -l ~/revcert.asc
-r--------   1 packaget  packaget  260 Oct 23 10:30 revcert.asc

Now you (the owner) are the only one who can read the file. Note that we’ve even removed write permissions for the owner.

Using your key from within your mail program

Since most folks use a GUI-based email client like Thunderbird or Mail.app, here are some add-ins that you can use with your mail client to provide GPG functionality. These make it really easy to use GPG with your mail, adding sign/encrypt options to the Compose window and automatic decryption for encrypted messages.

  • Enigmail is an extension for Mozilla Thunderbird. If you use Thunderbird or Mozilla/Netscape, this is the cheese.
  • GPGMail is a plug-in for Apple’s Mail.app. Although its authors claim that “GPGMail is a complete hack, relying on Mail’s internal private API,” I’ve been using it for several months without issue. The latest version even has an installer.

The difference between signing and encrypting

Signing an email message using your key helps prove that the message came from you. This isn’t the same as encrypting the message, but is a common way to assert the authenticity of the sender. Your message is still sent in plain text and anyone can read it, but they can also use your GPG signature to verify your identity. I tend to sign most of the messages I send.

Encrypting is another story. To encrypt a message, you need the public key of the person to whom you are sending the encrypted message. When you use someone’s public key to encrypt a message, only the person who has the corresponding secret key can decrypt it. So, if I wanted to send an encrypted message to ‘John’, I would need his public key.

Obtaining your public key

To obtain your public key (a big block of ASCII characters that looks like garbage text), use gpg -a --export from the command line:

$ gpg -a --export packagethief

This will print your key to the screen (the -a option tells GPG to output in ASCII text). Sometimes it’s more useful to have this in a text file so you don’t have to copy/paste it. To do so, just redirect the output to a file:

$ gpg -a --export packagethief > ~/pubkey.txt

This will save your key in the file pubkey.txt in your home directory. You can now publish your key (say, on your website), so that others can use it to send you encrypted messages.

Changing your passphrase

Until today, I didn’t even know you could do this. You change the passphrase for a key by editing it. Not everything is editable (for example, you can’t change your user ID), but changing your passphrase is the kind of thing you might want to do from time to time.

$ gpg --edit-key packagethief
Command> passwd

You’ll be asked for your existing passphrase before you’ll be able to type a new one. To exit and save your changes, type quit at the prompt.

Related resources

My public key

-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1.4.1 (Darwin)

mQGiBENbnh4RBAC7s8cQhyDkow6IgfIYpkflFQ5lmK8Hlc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KetADgGTy+A8iuI7t6RP/rOerPsAAwUH/2jNqxWexpvH5ZGwsWI2qBl5bghz
ofzTp4yxa/dj6LuU6rLfO4Rvob0avWjy8d2+b5ABvXfRM2BkZWjGP4s8sKJ1lRUM
pGfCw9N9ouraQMXyoG+R7/ZKQhECQipBRpm1l7T0VazQ/36RUEFBj2uEOoyv8H5H
uQ/s0/FQBZX2YU49vQ7ujBiutbRdedomx3dYw3kPpI9axagjGfJBgMhMOxZa0Dt8
pXico+KYFsXu26L3bacl73vSvCiqVRZfkDC06TvelR6yx/OGzxHPo6kFtjcUYGV1
wAHwdphcKd8Fy3+Xmi/Onpq4sXlBSL9IG1EW+eBISurCNOzsT2It8OVhun6ISQQY
EQIACQUCQ1ueJgIbDAAKCRCwvVj9bv2rJha9AJ4/FxF/ECoRvlV7w5MLVHnFv3PG
tACff4IWVTIMlABOm+o6aVfYliUUHb4=
=sLot
-----END PGP PUBLIC KEY BLOCK-----

FIGlet

Wednesday, October 19

Today I came across FIGlet, a little program for making large letters (signatures, banners, etc.) out of plain text.

I think I always vaguely pictured computer nerds sitting around for days on end painfully positioning pipes and underscores to create these obscure pieces of internet art. Now I know better.

You can download and install FIGlet from http://figlet.org, but if you’re using a package manager you’ll probably find there’s a port for it.

I use Darwin Ports on OSX and installation was trivial:

$ port install figlet

Once FIGlet has been downloaded and installed, start it up by typing figlet at the CLI and then type whatever you want. Alternatively, pipe a file or the output of another command through FIGlet, or put your input right on the command line as an argument.

$ figlet Hello World!

Now, go get working on your signature.

Setting up SSH keys is easy

Sunday, October 16

You can use SSH Keys to avoid having to enter your password when you log in to a remote machine. Think of your key as being your computer’s unique thumbprint. When you ssh into another computer, your thumbprint is checked against a list of pre-authorized thumbprints and if a match is found, you’re allowed in—no password required.

If you’ve never done this before, you’ll need to create a DSA key pair (the thumbprint). You only need to do this once.

$ ssh-keygen -d

Just hit enter to accept the defaults, and leave the passphrase blank. Your public key will be saved to the file ~/.ssh/id_dsa.pub

Now that you have a key, all you have to do is copy it to the authorized_keys file on the machine you want to log in to.

$ scp ~/.ssh/id_dsa.pub username@example.com:~/.ssh/authorized_keys

Nice. Now you’ll be able to log in without your password, which is really helpful when you want to do things like schedule backups using rsync, or if you’re lazy.

Just don’t lose your laptop.

Notes on Mail.app

Tuesday, September 27

When I first switched to the Mac, I installed and configured my favorite mail client, Thunderbird. OS X’s built-in mail client, Mail.app is (of course) gorgeous, and its tight integration with the OS is nice, but I was worried that it wouldn’t be up to snuff in its IMAP support, Spam filtering capabilities, and sorting features. Moreover, how I was going to use GPG to sign and encrypt my messages (a feature that’s easily added to Thunderbird by the Enigmail extension)? Well, my worrying was all in vain—as it turns out, Mail.app is more capable than I gave it credit for.

To be sure, Thunderbird has an impressive feature set: saved searches, message threading, Global Inboxes, and extension API to name a few. Well, as I found out, so does Mail.app. In fact, Mail.app has Smart Mailboxes which improve on saved searches, better threading features, and I even prefer the way multiple accounts are collected in the Global Inbox. In Thunderbird, you don’t get to group by individual accounts—they’re all just lumped together with no way to tell which is which without looking at the to header.

Spam filtering in Mail.app is just as good (if not better) than it is in Thunderbird, both of which use Bayesian filtering and cumulative rules to ‘learn’ what you consider to be Spam. Mail.app gets bonus points, however, because you can manually set additional rules in the same way you would filters to futher customize and refine things.

As for GPG (a feature I can’t do without), GPGMail for Mail.app is the answer I was looking for. For those who aren’t aware, GnuPG is a free PGP replacement. PGP stands for “Pretty Good Privacy”, and can be used to encrypt text (usually e-mail) and sign messages thus proving the identity of the original author. Simply put, GPGMail allows you to read and send PGP authenticated and/or encrypted messages right from inside Mail.app.

If anything, I’d say Mail.app has a more complete feature set than Thunderbird, although the latter makes up for this by virtue of its extension capabilities. That said, I use an extension in Thunderbird that adds a toolbar button to toggle normal/full headers of messages - in Mail.app, this feature exists out of the box. There’s also a toolbar button that toggles between threaded and un-threading message viewing - something I’ve always wished Thunderbird could do (and for which no extension exists).

Thunderbird is still highly regarded in by book due to the fact that it’s cross platform and open source (when you’re working on Mac, Windows, and Linux, it’s nice to have the same mail client accross the board). If Thunderbird were to improve its Mac support in a few areas, and were to support true OS X aqua theming, I would probably be using it in place of Mail.app for the reasons aforementioned. Sadly, it just feels out of place in an otherwise tightly knit environment. That said, Thunderbird (and Firefox for that matter) really shine on Linux—fast, responsive, and good looking.

A few tips

  • To add multiple email address for an account in Mail.app: In the Preferences for the account, enter all your addresses in the email address field, separated by commas. When composing a new message, you’ll get to select which address you’d like to use in the from header.
  • If you’re down with GPG, you might also be interested in the Mac GPG project which brings a bunch of GUI tools to OS X. Check out GPG Keychain Access which lets you manage and create keys using a friendly GUI, and GPGPreferences for a pretty preference pane in which you can manage GPG’s option file.