Last active
November 18, 2021 16:03
-
-
Save nicksieger/52c8aca61a0369818669ef555262c8d1 to your computer and use it in GitHub Desktop.
Publish Tilt resource statuses as macOS notifications
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Send a message to OSX Notification Center when Tilt finishes building resources | |
# | |
# usage: tiltnotify [options] | |
# | |
# Options are passed as command-line arguments to `tilt get` (e.g., --port). | |
notify() { | |
local title= subtitle= message= | |
title="$1" | |
shift | |
subtitle="$1" | |
shift | |
message="$@" | |
cat <<EOF | osascript - | |
display notification "$message" with title "$title" subtitle "$subtitle" | |
EOF | |
} | |
IFS=: | |
# Don't trigger a notification for these statuses so that notification center is | |
# not too noisy | |
ignore_statuses=( in_progress not_applicable pending ) | |
statuses=( ) | |
loop=1 | |
while [ "$loop" ]; do | |
tilt get "$@" --watch-only uiresources -o jsonpath='{.metadata.name}{":"}{.status.updateStatus}{"\n"}' | \ | |
while read resource status; do | |
if [ "${statuses[$resource]}" = "$status" ]; then | |
continue | |
fi | |
statuses[$resource]=$status | |
if [[ "${ignore_statuses[@]}" =~ $status ]]; then | |
echo Ignoring $resource $status | |
continue | |
fi | |
echo $resource updated: $status | |
notify Tilt $resource $status | |
done | |
exitst=$? | |
pipest=( ${PIPESTATUS[@]} ) | |
echo tilt get exited -- s: $exitst pipestatus: ${pipest[@]} | |
if [ $exitst = 1 ]; then | |
loop= | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment