Bash alias to create a TracGit link to your latest commit

I’d like to share with you a handy bash alias to create a TracGit link to your latest commit.

Don’t forget to add the TracGit link

Who doesn’t use git? Nobody, that’s who. And who doesn’t use trac? Well, actually, a lot of people. Nowadays Joomla seems to be all the rage. But trac is pretty cool and I use it for all the things! TracGit lets you setup your git repos so that you can link to your source from the trac tickets and wiki pages.

As we all know by now, it’s a very, very good habit to link to your source changes when you close a ticket. In fact, I get to do that all the time. And whether it’s a single commit, or a merge from an entire branch of commits, it’s almost always the last change that you want to link to. So here’s a bash alias that gives you the exact trac syntax that you can copy from the shell and paste into your ticket.

alias git-trac='echo [changeset:$(git log -1 --format="%h")/$(basename $(git rev-parse --show-toplevel))];';

It’s nothing fancy, but I find myself using it all the time so I decided to share. Add it to your ~/.bashrc, or better yet, to ~/.bash_aliases, if you’re the organized type.

One less step…

If you’re anything like me, you’re way too busy to copy and paste stuff. If only you could skip one of those two steps and save valuable time…

Luckily, you can automate the copy to clipboard part! First install xclip:

sudo apt-get install xclip

Then, your alias becomes:

alias git-trac='echo [changeset:$(git log -1 --format="%h")/$(basename $(git rev-parse --show-toplevel))] | xclip -selection clipboard';

Unfortunately, you’ll have to paste the string into trac yourself. If you’re thinking about automating that part, well, then I’ve got to ask, what’s wrong with you?

Leave a Reply

Your email address will not be published. Required fields are marked *