Skip to content

Instantly share code, notes, and snippets.

@dschneller
Last active August 29, 2015 14:01
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dschneller/0195b025f0703657030f to your computer and use it in GitHub Desktop.
Save dschneller/0195b025f0703657030f to your computer and use it in GitHub Desktop.
#!/bin/bash -x
REPO="${1}"
SHA1="${2}"
OPEN="${3}"
repofragment=$(cd "$REPO"; git remote -v | grep origin | grep push | sed -e 's/.*github\.com.\(.*\)\.git.*/\1/')
url="https://github.com/${repofragment}/commit/${SHA1}"
echo "${url}" | pbcopy
[ -z "${OPEN}" ] || open "$url"
@dschneller
Copy link
Author

Shell script designed to be used as an External Action in SourceTree to copy the selected commit's GitHub URL into the clipboard and optionally also open the selected commit on the GitHub website.

To use it, go to SourceTree Preferences, select the Custom Actions tab and add a new action.
Menu Caption: Open in GitHub
Script to Run: Path to where you put this script
Parameters: $REPO $SHA [yes]

Optionally define keyboard shortcut.

Now in any place where you can select a commit in SourceTree, hit your shortcut to invoke the script.
Any third parameter will cause commit to be opened on the GitHub website.
I wanted to have this to quickly comment on commits.

If you just need the URL in the clipboard without opening it, leave the third parameter out.
I have both variants on different keyboard shortcuts (Shift-G and Ctrl-Shift-G) in my SourceTree.

@kriskhaira
Copy link

Thanks for this! Works for me on SourceTree v2.0.5.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment