Skip to content

Instantly share code, notes, and snippets.

@arai-ta
Last active March 27, 2018 15:50
Show Gist options
  • Save arai-ta/e725e16200888b2133937d43a786a0d5 to your computer and use it in GitHub Desktop.
Save arai-ta/e725e16200888b2133937d43a786a0d5 to your computer and use it in GitHub Desktop.
open current branch (+ specified file) in browser (GitHub)
#!/bin/bash
# newer version is available in https://github.com/arai-ta/git-open
set -e
set -u
#set -x
if ! git show >/dev/null
then
exit 1
fi
url=$(git remote -v | \
awk '
$3 ~ /fetch/{
url=$2;
sub(/:/,"/",url);
sub(/git@/,"https://",url);
sub(/\.git$/,"",url);
print url
}')
if [ "${1:-}" -a -e "${1:-}" ]
then
path=$1
br=$(git branch | \
awk '
/^\*/{
print $2
}')
url=$url/blob/$br/$path
fi
echo $url
open $url
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment