From eeb87c5bfc0b48382b7ee13aaef2281c9d66af09 Mon Sep 17 00:00:00 2001 From: Geoffray Levasseur-Brandin Date: Thu, 19 Jun 2025 14:34:22 +0200 Subject: [PATCH] make delay parametrable --- profile.d/fun.sh | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) 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 }