-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgithub
executable file
·32 lines (27 loc) · 871 Bytes
/
github
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
#!/bin/bash
BASE_URL=$(git remote get-url origin | sed 's/^github:/https:\/\/github.com\//')
[ -n "$BASE_URL" ] || exit 1
get_branch_suffix() {
BRANCH=$(git br)
if [ -n "$BRANCH" -a "$BRANCH" != "main" -a "$BRANCH" != "master" ]; then
echo ${1}/${BRANCH}
elif [ "${2:-1}" != 0 ]; then
echo $1
fi
}
open_page() {
PAGE_NAME=$1
[ -n "$3" ] && PAGE_NAME=$2
URL=$(echo "${BASE_URL}/$PAGE_NAME/$3" | sed 's/\/*$//')
($BROWSER "$URL" &> /dev/null &)
exit
}
case $1 in
c|commit|commits) open_page $(get_branch_suffix commits) commit $2 ;;
h|head) open_page commit ;;
i|issue|issues) open_page issues issues $2 ;;
p|pull|pulls|pr|prs) open_page pulls pull $2 ;;
a|actions|ci) open_page actions ;;
s|settings) open_page settings ;;
*) open_page $(get_branch_suffix tree 0) ;;
esac