Skip to content

Instantly share code, notes, and snippets.

@gzur
Created February 20, 2020 22:26
Show Gist options
  • Save gzur/ad7eece31f46c0b5d9c95f6e40c72de0 to your computer and use it in GitHub Desktop.
Save gzur/ad7eece31f46c0b5d9c95f6e40c72de0 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
# Only tested on Mac
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 gitlab_url (echo $remote | sed 's/\:/\//g' | sed 's/git@/https\:\/\//g' | sed 's/\.git$//g')
set arg $argv[1]
switch (echo $arg)
case p pi pip pipe pipeline pipelines
set gitlab_url $gitlab_url/pipelines
case m mr mrs merge
set gitlab_url $gitlab_url/merge_requests
case d r docker reg registry
set gitlab_url $gitlab_url/container_registry
case url u
echo $gitlab_url | pbcopy
echo "Git remote \"$gitlab_url\" copied to clipboard"
return 0
case '*'
echo $gitlab_url
end
echo "Opening gitlab url "$gitlab_url
open $gitlab_url
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment