Last active
March 27, 2018 15:50
-
-
Save arai-ta/e725e16200888b2133937d43a786a0d5 to your computer and use it in GitHub Desktop.
open current branch (+ specified file) in browser (GitHub)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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