-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdo.sh
72 lines (57 loc) · 1.29 KB
/
do.sh
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash
# 2019 © Postgres.ai
run() {
set -x
make dep
make all
set +x
# Read and set git status info if it wasn't done before.
if [ "$INCLUDE_GIT_STATUS" == "true" ] && [ -z "$GIT_COMMIT_HASH" ]; then
echo "Fetching git status..."
export_git_status
fi
set -x
./bin/joe
}
export_git_status() {
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
GIT_STATUS_RES=$(cd $DIR && git status --porcelain=v2 -b)
EXIT_CODE=$?
if [ $EXIT_CODE != 0 ]; then
echo "git exit code: ${EXIT_CODE}"
exit
fi
GIT_MODIFIED="false"
GIT_BRANCH=""
GIT_COMMIT_HASH=""
while read -r line; do
COLUMNS=($line)
if [ ${#COLUMNS[@]} > 3 ]; then
if [ ${COLUMNS[1]} == "branch.oid" ]; then
GIT_COMMIT_HASH=${COLUMNS[2]}
continue
elif [ ${COLUMNS[1]} == "branch.head" ]; then
GIT_BRANCH=${COLUMNS[2]}
continue
fi
fi
GIT_MODIFIED="true"
done <<< "$GIT_STATUS_RES"
export GIT_MODIFIED
export GIT_BRANCH
export GIT_COMMIT_HASH
}
is_command_defined() {
type $1 2>/dev/null | grep -q 'is a function'
}
# Parse command and arguments.
COMMAND=$1
shift
ARGUMENTS=${@}
# Run command.
is_command_defined $COMMAND
if [ $? -eq 0 ]; then
$COMMAND $ARGUMENTS
else
echo "Command not found"
fi