Skip to content

Instantly share code, notes, and snippets.

@mrabbitt
Created July 5, 2012 03:41
Show Gist options
  • Save mrabbitt/3051104 to your computer and use it in GitHub Desktop.
Save mrabbitt/3051104 to your computer and use it in GitHub Desktop.
Wrapper for SourceTree "stree" command which works on any file or directory nested inside inside a Git or Mercurial repo.
#!/bin/bash -e
getRepoRoot()
{
local target=$1
if [ -d "${target}" ] ; then
cd "${target}"
elif [ -f "${target}" ] ; then
cd "$(dirname ${target})"
fi
echo $(git rev-parse --show-toplevel 2>/dev/null || hg root 2>/dev/null)
}
STREE_EXE='stree'
if ! type "${STREE_EXE}" ; then
if [ -x '/Applications/SourceTree.app/Contents/Resources/stree' ] ; then
STREE_EXE='/Applications/SourceTree.app/Contents/Resources/stree'
fi
fi
repo_root_path=$(getRepoRoot "${1:-${PWD}}")
"$STREE_EXE" "${repo_root_path}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment