Added: Possibilty to run date through background fifo for bash <5

pull/104/head
aristocratos 2020-05-05 21:34:48 +02:00
parent 1692f22fd9
commit 576c391575
1 changed files with 28 additions and 8 deletions

36
bashtop
View File

@ -200,16 +200,36 @@ if [[ -n $EPOCHREALTIME ]]; then
ms_out=$((${EPOCHREALTIME/[.,]/}/1000)) ms_out=$((${EPOCHREALTIME/[.,]/}/1000))
} }
#* If not, use date command #* If not, use date command, through fifo if possible
else else
get_ms() { #? Set given variable to current epoch millisecond with date command tmpdir=""
local count if [[ -n $XDG_RUNTIME_DIR && -w "$XDG_RUNTIME_DIR" ]]; then
local -n ms_out=$1 tmpdir="$XDG_RUNTIME_DIR"
ms_out="" elif [[ -w /dev/shm ]]; then
while [[ -z $ms_out ]] && ((++count<=10)); do tmpdir="/dev/shm"
elif [[ -w /tmp ]]; then
tmpdir="/tmp"
fi
if [[ -n $tmpdir ]] && command -v stdbuf >/dev/null 2>&1; then
mkfifo "${tmpdir}/bashtop_datefifo"
exec 5> >(exec stdbuf -o0 date -f - +%s%3N > "${tmpdir}/bashtop_datefifo" 2>&1)
exec 6< "${tmpdir}/bashtop_datefifo"
rm "${tmpdir}/bashtop_datefifo"
get_ms() { #? Set given variable to current epoch millisecond with date command through background fifo
local -n ms_out=$1
echo now >&5 &&
read -u 6 ms_out
}
else
get_ms() { #? Set given variable to current epoch millisecond with forked date command
local -n ms_out=$1
ms_out=""
read ms_out < <(date +%s%3N) read ms_out < <(date +%s%3N)
done }
} fi
fi fi
init_() { #? Collect needed information and set options before startig main loop init_() { #? Collect needed information and set options before startig main loop