-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgitgo.plugin.zsh
executable file
·58 lines (52 loc) · 1.42 KB
/
gitgo.plugin.zsh
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/zsh
if [[ "$OSTYPE" = darwin* ]] || [[ "$OSTYPE" = linux* ]] ; then
if [[ "command -v open" ]] || [[ "command -v xdg-open" ]] ; then
function gitgo() {
local PRPATH="/compare"
local OPEN
local EREGEX
local VS
local url
local finalurl
local branch
if [[ "$OSTYPE" = darwin* ]] ; then
OPEN=open
EREGEX=-E
else
OPEN=xdg-open
EREGEX=-r
fi
if [[ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ]]; then
url="$(git remote get-url origin)"
if [[ $url = *"visualstudio.com"* ]] || [[ $url = *"azure.com"* ]] ; then
VS=true
finalurl=$(sed "$EREGEX" -e 's|.*@.+:.+/([a-z]+)/(.+)/(.+)|https://\1\.visualstudio.com/\2/_git/\3|' <<< "$url")
else
VS=false
if [[ $url = *"https"* ]]; then
finalurl=$(sed 's_\.git__' <<< "$url")
else
finalurl=$(sed -e 's_:_/_' -e 's_git@_https://_' -e 's_\.git__' <<< "$url")
fi
fi
if [[ $1 == "comp" ]]; then
$OPEN "$finalurl$PRPATH"
elif [[ $1 == "pr" ]]; then
branch="$(git rev-parse --abbrev-ref HEAD)"
if [[ "$VS" = true ]]; then
$OPEN "$finalurl/pullrequestcreate?sourceRef=$branch&targetRef=master"
else
$OPEN "$finalurl$PRPATH/$branch?expand=1"
fi
else
$OPEN "$finalurl"
fi
else
echo 'Sorry. The current directory is not inside a git work tree.'
fi
}
alias ghg='gitgo'
alias ghc='gitgo comp'
alias ghp='gitgo pr'
fi
fi