#!/bin/bash
errors="${1:-tsc-w-errors.log}"
errors1="${2:-errors.err}"
debounce=1.5
(echo init; inotifywait -q -m -e modify "$errors") | while read -r F; do
    read -t $debounce -d$'\1' MORE
    <"$errors" tac | sed '/\x1bc/ { s/\x1bc//; q }' |
    sed 's/\<src\///' |
    grep -vE '^[0-9]|^$' >"$errors1"
    if [ -s "$errors1" ]; then 
        notify-send -u critical "compile errors" "`<"$errors1"`"
    else
        notify-send "compile okay"
    fi
done
