diff --git a/profile.d/fun.sh b/profile.d/fun.sh index 530c758..33c75c8 100644 --- a/profile.d/fun.sh +++ b/profile.d/fun.sh @@ -88,19 +88,23 @@ busy() esac done - # If a pattern was provided as a positional argument (e.g., 'busy "ff 00"'), - # it is captured here. - [[ -n "$1" ]] && pattern="$1" - # Convert milliseconds to seconds for 'sleep' - local delay_s=$(awk "BEGIN { printf \"%.3f\", $delay_ms / 1000 }") + local delay_s=$(awk "BEGIN{ + printf \"%.3f\", $delay_ms / 1000 }") # Monitor /dev/urandom - cat /dev/urandom | hexdump -C | grep --line-buffered "$pattern" | \ - while read -r line; do - echo "$line" - [[ $delay_ms -gt 0 ]] && sleep "$delay_s" - done + ( + hexdump -C < /dev/urandom | grep -iF --line-buffered "$pattern" | \ + while read -r line; do + echo "$line" + [[ $delay_ms -gt 0 ]] && sleep "$delay_s" + done + ) & local sub_pid=$! + + IFS= read -r -n 1 -s _ /dev/null || kill "$sub_pid" 2>/dev/null + wait "$sub_pid" 2>/dev/null + return 0 } # ------------------------------------------------------------------------------