Skip to content

Instantly share code, notes, and snippets.

@gzur
Last active February 20, 2020 22:32
Show Gist options
  • Save gzur/6858866cdae7324818430a34777f05e8 to your computer and use it in GitHub Desktop.
Save gzur/6858866cdae7324818430a34777f05e8 to your computer and use it in GitHub Desktop.
Infers the github/gitlab/bitbucket link from your git remote
# Git Link.
# Infers the github/gitlab/bitbucket link from your git remote
# and opens it in your default browser.
# I mostly use gitlab, so there is some extra options for that (`gl p` / `gl m` / `gl d`)
# 1. cd into a directory containing a git repo
# 2. run `gl`
# 3. Profit!!!
# Only tested on Mac - other OSes are left as an exercise to the reader.
function gl
git rev-parse --is-inside-work-tree >/dev/null
if test "$status" -gt 0
return $status
end
set remote (git remote get-url --all origin)
if string match -q -- "https*" $remote
echo "Opening url "$remote
open $remote
return 0
end
set git_link (echo $remote | sed 's/\:/\//g' | sed 's/git@/https\:\/\//g' | sed 's/\.git$//g')
set arg $argv[1]
switch (echo $arg) # gitlab subpage shenanigans
case p pi pip pipe pipeline pipelines
set git_link $git_link/pipelines
case m mr mrs merge
set git_link $git_link/merge_requests
case d r docker reg registry
set git_link $git_link/container_registry
case url u
echo $git_link | pbcopy # not very portable
echo "Git remote \"$git_link\" copied to clipboard"
return 0
case '*'
echo $git_link
end
echo "Opening gitlab url "$git_link
open $git_link # not very portable - or maybe it is. I have no idea.
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment