-
-
Save rtio/66b748b148e31ab4dc4b7136f58ab391 to your computer and use it in GitHub Desktop.
Updated anybar script
This file contains hidden or 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 | |
| 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 | |
| # Regexes | |
| WEBPACK_COMPILED_SUCCESSFULLY_REGEX="^webpack.*compiled successfully" | |
| WEBPACK_COMPILED_WITH_WARNINGS_REGEX="^webpack.*compiled with.*warnings" | |
| WEBPACK_BUILDING_REGEX="webpack building" | |
| WEBPACK_COMPILED_WITH_ERROR_REGEX="webpack.*compiled with.*error" | |
| ERROR_REGEX="ERROR" | |
| RESTARTING_DUE_TO_CHANGES_REGEX="restarting due to changes" | |
| APP_CRASHED_REGEX="app crashed" | |
| TEST_ERROR_REGEX="^[0-9]+\ failing$" | |
| # Handle Ctrl+C to reset icon | |
| trap 'reset_icon; exit 0' SIGINT | |
| main() { | |
| reset_icon | |
| tee >(update_status) | |
| } | |
| update_status() { | |
| while read line | |
| do | |
| if [[ "$line" =~ $WEBPACK_COMPILED_SUCCESSFULLY_REGEX ]] || [[ "$line" =~ $WEBPACK_COMPILED_WITH_WARNINGS_REGEX ]]; then | |
| if [ $HAS_ERROR -eq 0 ]; then | |
| set_icon "$DONE_COLOR" | |
| else | |
| set_icon "$BUILD_ERROR_COLOR" | |
| fi | |
| elif [[ "$line" =~ $WEBPACK_BUILDING_REGEX ]]; then | |
| HAS_ERROR=0 | |
| set_icon "$PROGRESS_COLOR" | |
| elif [[ "$line" =~ $WEBPACK_COMPILED_WITH_ERROR_REGEX ]]; then | |
| HAS_ERROR=1 | |
| set_icon "$BUILD_ERROR_COLOR" | |
| elif [[ "$line" =~ $ERROR_REGEX ]]; then | |
| HAS_ERROR=1 | |
| # for `npm run test-client:watch` | |
| elif [[ "$line" =~ $RESTARTING_DUE_TO_CHANGES_REGEX ]]; then | |
| reset_icon | |
| # for both test-client and test-client:watch | |
| elif [[ "$line" =~ $APP_CRASHED_REGEX ]] || [[ "$line" =~ $TEST_ERROR_REGEX ]]; 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