-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit-open
More file actions
executable file
·27 lines (21 loc) · 858 Bytes
/
git-open
File metadata and controls
executable file
·27 lines (21 loc) · 858 Bytes
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
#!/usr/bin/env bash
set -e
if [[ $1 == "commit" ]]; then
COMMIT_URL=$(git config --local --default "" remote.origin.commitUrl | sed "s/\/\{0,1\}$//")
if [[ ! -n ${COMMIT_URL} ]]; then
echo "Git config remote.origin.commitUrl is required but it isn't set"
echo "e.g.: git config --local remote.origin.commitUrl \"https://github.com/jmera/bin/commit/\""
exit 1
fi
COMMIT=${2-$(git rev-parse HEAD)}
open "$COMMIT_URL/$COMMIT"
elif [[ $1 == "tree" ]]; then
TREE_URL=$(git config --local --default "" remote.origin.treeUrl | sed "s/\/\{0,1\}$//")
if [[ ! -n ${TREE_URL} ]]; then
echo "Git config remote.origin.treeUrl is required but it isn't set"
echo "e.g.: git config --local remote.origin.treeUrl \"https://github.com/jmera/bin/tree/\""
exit 1
fi
COMMIT=${2-$(git rev-parse HEAD)}
open "$TREE_URL/$COMMIT"
fi