diff --git a/profile.d/fun.sh b/profile.d/fun.sh index a42b86c..b7f08a0 100644 --- a/profile.d/fun.sh +++ b/profile.d/fun.sh @@ -39,12 +39,30 @@ # ------------------------------------------------------------------------------ busy() { - if [[ -n $1 ]]; then - local pattern="$@" - else - local pattern="ca fe" - fi - cat /dev/urandom | hexdump -C | grep "$pattern" + local pattern="ca fe" + for arg in "$@"; do + case "$arg" in + --delay=*) + delay_ms="${arg#*=}" + if ! [[ $delay_ms =~ ^[0-9]+$ ]]; then + disp E "Invalid delay value, must be an integer (milliseconds)." + return 1 + fi + ;; + *) + pattern="$arg" + ;; + esac + done + + # Convert milliseconds to seconds for 'sleep' + local delay_s=$(awk "BEGIN { printf \"%.3f\", $delay_ms / 1000 }") + + cat /dev/urandom | hexdump -C | grep --line-buffered "$pattern" | \ + while read -r line; do + echo $line + [[ $delay_ms -gt 0 ]] && sleep "$delay_s" + done unset pattern }