-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepo
executable file
·44 lines (33 loc) · 1.37 KB
/
repo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env bash
set -euo pipefail
function open(){
if which open &>/dev/null; then
command open "${@:-}";
elif which xdg-open &>/dev/null; then
command xdg-open "${@:-}";
else
echo "open: ${@:-}"
fi
}
urls=$( git remote | xargs -I{} git remote get-url {} )
topPath=$( git rev-parse --show-toplevel )
subpath="${1:-$PWD}"
subpath=$( readlink -f "$subpath" )
subpath="${subpath#$topPath}"
branchName=$( git branch --show-current )
if url=$( echo "$urls" | grep dev.azure.com | head -n 1 ); then
# example: [email protected]:v3/bushelpowered/terraform/unified-iac
read org project repo < <( echo "$url" | rev | cut -d/ -f1-3 | rev | tr '/' ' ' );
open "https://dev.azure.com/$org/$project/_git/$repo/?version=GB${branchName}&path=$subpath"
elif url=$( echo "$urls" | grep '[email protected]' | head -n 1 ); then
# example: [email protected]:myriadmobile/systems-utils.git
urlPath=$( echo "$url" | cut -d: -f2 | sed 's/\.git.*$//' )
open "https://bitbucket.org/${urlPath}/src/${branchName}/${subpath}"
elif url=$( echo "$urls" | grep '[email protected]' | head -n 1 ); then
# example: [email protected]:bushelpowered/terraform-provider-oncall.git
urlPath=$( echo "$url" | cut -d: -f2 | sed 's/\.git$//' )
open "https://github.com/${urlPath}/"
else
>&2 echo "Not in an azdo backed repo: $urls"
exit 1
fi