Skip to content

Instantly share code, notes, and snippets.

@mcsf
Last active June 23, 2021 11:56
Show Gist options
  • Save mcsf/56911ae03c6d87ec61429cefc7707cb7 to your computer and use it in GitHub Desktop.
Save mcsf/56911ae03c6d87ec61429cefc7707cb7 to your computer and use it in GitHub Desktop.
Calypso AnyBar handler
#!/bin/bash
PORT="${PORT:-1738}"
DONE_COLOR="${DONE_COLOR:-"black"}"
PROGRESS_COLOR="${PROGRESS_COLOR:-"white"}"
INITIAL_COLOR="${INITIAL_COLOR:-"white"}"
BUILD_ERROR_COLOR="${BUILD_ERROR_COLOR:-"red"}"
TEST_ERROR_COLOR="${TEST_ERROR_COLOR:-"purple"}"
HAS_ERROR=0
main() {
reset_icon
tee >(update_status)
}
update_status() {
while read line
do
if [[ "$line" =~ "webpack: Compiled successfully." ]]; then
if [ $HAS_ERROR -eq 0 ]; then
set_icon "$DONE_COLOR"
else
set_icon "$BUILD_ERROR_COLOR"
fi
elif [[ "$line" =~ "webpack: Compiling..." ]]; then
HAS_ERROR=0
set_icon "$PROGRESS_COLOR"
elif [[ "$line" =~ "ERROR" ]]; then
HAS_ERROR=1
# for `npm run test-client:watch`
elif [[ "$line" =~ "restarting due to changes" ]]; then
reset_icon
# for both test-client and test-client:watch
elif [[ "$line" =~ "app crashed" ]] || [[ "$line" =~ ^[0-9]+\ failing$ ]]; then
set_icon "$TEST_ERROR_COLOR"
fi
done
}
set_icon() {
echo -n "$1" | nc -4u -w0 localhost $PORT
}
reset_icon() {
if [ "$INITIAL_COLOR" != "" ] && [ "$INITIAL_COLOR" != "none" ]; then
set_icon "$INITIAL_COLOR"
fi
}
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment