Saturday, August 22, 2009

An easier way to compose Thunderbird mail from the command line

For sometime, I had wished for an easier way to attach the output of diff to a new Thunderbird mail than the following:
  1. diff -u file1 file2 >/tmp/mypatch
  2. Switch to Thunderbird
  3. Click the "Write" icon
  4. Click the "Attach" icon in the compose mail window
  5. Browse to the file
  6. Click the "Open" button to finally attach the file
Turns out, TB's compose mail window can be created from the command-line by passing the -compose option to thunderbird. However, passing the mail parameters like "to", "subject", "attachment", etc. via this command is quite ugly:
thunderbird -compose "to='john@example.com',subject='dinner',body='How about dinner tonight?',attachment='file:///tmp/food.doc'"

To get over this mess, and sort out my original problem with the attachments, I wrote a small script called tb-compose:
http://github.com/chaitanyagupta/misc-utils/blob/master/tb-compose
Example usage:
tb-compose --to john@example.com --subject dinner --body "How about dinner tonight?" --attachment /tmp/food.doc

Moreover, if - is passed as a value for --attachment, the contents of standard input are attached to the mail.
diff -u file1 file2 | tb-compose --attachment -

And if --attachment-name is used when stdin is being attached, the given name is used as the name for the attached file.
diff -u file1 file2 | tb-compose --attachment - --attachment-name mypatch

Makes my life a little easier :-)

Labels: ,



Friday, August 21, 2009

A couple of hooks to make life easy with git submodules

While using git at work for the last few weeks, I noticed a couple of issues with the usage of git-submodules.
  1. Submodules updated in commits when not intended to be -- more or less due to over-enthusiastic usage of git commit -a.
  2. Failure to run git-submodule update after a git-merge (git-pull) or git-checkout.
To help with these issues, I wrote a couple of git hooks. They can be pulled from my gitutils repository on github:
http://github.com/chaitanyagupta/gitutils/tree
Three git-hooks can be found in the submodule-hooks/ directory: pre-commit, post-merge and post-checkout (post-merge-checkout provides the latter two).

pre-commit checks if any submodules have been updated in the index and are about to be committed. If so, it asks user for confirmation to go ahead with the commit.

post-merge-checkout checks if any submodules have been modified in the working tree (i.e. their git-status is "modified" under "Changed but not updated") after a branch checkout or merge. If that is the case, it asks the user if they want to run git submodule update.

Hope someone will find them useful.

Labels:



This page is powered by Blogger. Isn't yours?

Subscribe to Posts [Atom]