-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotify
executable file
·35 lines (31 loc) · 868 Bytes
/
notify
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
#!/bin/bash
SECONDS=0
bash -c "$*"
EXIT_STATUS=$?
ELAPSED_HOURS=$((SECONDS / 3600))
ELAPSED_MINUTES=$(((SECONDS / 60) % 60))
ELAPSED_SECONDS=$((SECONDS % 60))
ELAPSED=""
if [[ $ELAPSED_HOURS -ne 0 ]]; then
ELAPSED="${ELAPSED_HOURS}h"
fi
if [[ $ELAPSED_MINUTES -ne 0 ]]; then
if [[ -n $ELAPSED ]]; then
ELAPSED+=" "
fi
ELAPSED+="${ELAPSED_MINUTES}m"
fi
if [[ $ELAPSED_SECONDS -ne 0 ]]; then
if [[ -n $ELAPSED ]]; then
ELAPSED+=" "
fi
ELAPSED+="${ELAPSED_SECONDS}s"
fi
if [[ "$EXIT_STATUS" -eq 0 ]]; then
gsconnect --notification "Success ($ELAPSED)" --notification-body "$*"
echo "Command '$*' succeeded after $ELAPSED"
else
gsconnect --notification "Failure [\$?=$EXIT_STATUS] ($ELAPSED)" --notification-body "$*"
echo "Command '$*' failed with status $EXIT_STATUS after $ELAPSED"
fi
exit "$EXIT_STATUS"