Opening Sourcetree from TextMate

by 4/10/2015 03:09:00 PM 2 comments

My goto editor these days is TextMate. (The recent 2.0 releases have been really great). Like many developers, I use git for source control. Most of the time I use git on the command line, but once in a while I'll open up a project in the very awesome, and very free SourceTree VCS Gui from Atlassian. To simplify opening a project in SourceTree when working from TextMate I added a command via TextMate's extremely simple and flexible Bundles. (Which, due to the simplicity and flexibility of bundle's in TextMate, just tromps on anything I've seen in any other text editor, sorry Sublime Text.).

First, you will need to install SourceTree. Once installed, launch it and select SourceTree > Install Command Line Tools to install the stree shell command.

To add the command to TextMate, do the following:

  1. In TextMate, go to Bundles > Edit Bundles
  2. Select the Bundle that you want to add your command to. I created one with my own name, but you can use existing ones.
  3. Hit [command]+N to open a dialog to Create a New Item
  4. In the Create New Item dialog choose Command
  5. In the sidebar, name it Open With SourceTree. Add your favorite key equivalent (I use [command]+. )
  6. Set Save to Nothing
  7. Set Input to Nothing
  8. Set Output to Discard
  9. In the script shell at the bottom enter the following:
    
    #!/usr/bin/env bash
    if [ -d $TM_DIRECTORY ] ; then
      cd $TM_DIRECTORY 
    elif [ -d $TM_PROJECT_DIRECTORY ] ; then
      cd $TM_PROJECT_DIRECTORY
    fi
      
    GIT_ROOT=$(git rev-parse --show-toplevel)
    if [ -d $GIT_ROOT ] ; then
      stree $GIT_ROOT
    fi
      
And that's it. Enjoy.

hohonuuli

Developer

Cras justo odio, dapibus ac facilisis in, egestas eget quam. Curabitur blandit tempus porttitor. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.

2 comments:

Graham P Heath said...

Thanks for your post. I hope you dont mind me making your work available via GitHub: https://github.com/loadedsith/SourceTree.tmbundle.

The better to share / contribute / file issues :)

hohonuuli said...

I don't mind at all. Good work and thanks for sharing the credit.