Skip to content

Instantly share code, notes, and snippets.

@BaseCase
Last active December 18, 2015 17:19
Show Gist options
  • Select an option

  • Save BaseCase/5817645 to your computer and use it in GitHub Desktop.

Select an option

Save BaseCase/5817645 to your computer and use it in GitHub Desktop.
GitHub Blame: given a filename argument, this will open GitHub's Git Blame view on that file in your current repo and branch.
#!/bin/bash
set -e
filename=$1
function repo_name {
git remote -v |
grep -m 1 "git@.*\.git" |
awk '{print $2}' |
cut -d ':' -f 2 |
sed s/\.git//
}
function branch_name {
git status |
grep "On branch" |
cut -d ' ' -f 4
}
function path_to_file {
git ls-files --full-name $filename
}
function github_blame_url {
echo "https://github.com/$(repo_name)/blame/$(branch_name)/$(path_to_file)"
}
open `github_blame_url`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment