Skip to content

Instantly share code, notes, and snippets.

@andfinally
Forked from mcsf/calypso-anybar-handler.sh
Last active April 25, 2018 17:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andfinally/0fe46c3b08e394cc9f8e947881a57cde to your computer and use it in GitHub Desktop.
Save andfinally/0fe46c3b08e394cc9f8e947881a57cde to your computer and use it in GitHub Desktop.
Calypso AnyBar handler
#!/bin/bash
PORT="${PORT:-1738}"
DONE_COLOR="${DONE_COLOR:-"green"}"
PROGRESS_COLOR="${PROGRESS_COLOR:-"orange"}"
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" = *"Compiled successfully."* ]]; then
if [ $HAS_ERROR -eq 0 ]; then
set_icon "$DONE_COLOR"
else
set_icon "$BUILD_ERROR_COLOR"
fi
elif [[ "$line" = *"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
@andfinally
Copy link
Author

andfinally commented Apr 25, 2018

This fork of https://gist.github.com/mcsf/56911ae03c6d87ec61429cefc7707cb7 changes DONE_COLOR and PROGRESS_COLOR, and uses wildcard string comparison with $line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment