Last active
May 22, 2022 06:57
-
-
Save snatchev/34e793af8ab1114d9e42 to your computer and use it in GitHub Desktop.
a fish-shell function to open the current git repo/branch in a browser
This file contains hidden or 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
function gh --description 'Open the webpage for the current github repo/branch' | |
set -l fetch_url (command git remote --verbose show -n origin ^/dev/null | command grep Fetch | cut -c 14- ) | |
#did we get an exit status? | |
if [ $status -gt 0 ] | |
echo 'Not a git repo.' | |
return 1 | |
end | |
if [ -z $fetch_url ] | |
echo 'Not a git repo.' | |
return 1 | |
end | |
if [ -z (echo $fetch_url | grep github ) ] | |
echo 'Not a github repo.' | |
return 3 | |
end | |
set -l branch (command git rev-parse --abbrev-ref HEAD) | |
if [ $branch = 'HEAD' ] | |
# we couldn't find a branch or tag, so lets get a sha | |
set branch (command git rev-parse HEAD) | |
end | |
set url (echo "$fetch_url/tree/$branch" | sed 's|[email protected]:\(.*\)\.git|https://github.com/\1|') | |
open "$url/$argv" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment