Skip to content

Instantly share code, notes, and snippets.

@armcknight
Created January 29, 2022 00:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save armcknight/cb561c35812f35ec61dc71c4c02627cf to your computer and use it in GitHub Desktop.
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
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