Created
January 29, 2022 00:59
-
-
Save armcknight/cb561c35812f35ec61dc71c4c02627cf to your computer and use it in GitHub Desktop.
construct a GitHub URL with a filename and optionally line number/range in the current repo/branch
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 gurl -a filePath lineNumber rangeEndLineNumber -d "create a URL for a file on GitHub's website, for the current repo and working branch, optionally with a line number or range" | |
set branchname (git rev-parse --abbrev-ref HEAD) | |
set repourl (git config --get remote.origin.url | sed s/\\.git// | sed 's/:/\//' | sed 's/.*github.com/https:\/\/github.com/') # h/t https://gist.github.com/richardmcmillen-examtime/7448300 | |
if test (count $argv) -eq 3 | |
echo $repourl/blob/$branchname/$filePath\#L$lineNumber-L$rangeEndLineNumber | |
else if test (count $argv) -eq 2 | |
echo "$repourl/blob/$branchname/$filepath#L$lineNumber" | |
else | |
echo $repourl/blob/$branchname/$filePath | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment