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

30
bashtop
View File

@ -200,17 +200,37 @@ if [[ -n $EPOCHREALTIME ]]; then
ms_out=$((${EPOCHREALTIME/[.,]/}/1000))
}
#* If not, use date command
#* If not, use date command, through fifo if possible
else
get_ms() { #? Set given variable to current epoch millisecond with date command
local count
tmpdir=""
if [[ -n $XDG_RUNTIME_DIR && -w "$XDG_RUNTIME_DIR" ]]; then
tmpdir="$XDG_RUNTIME_DIR"
elif [[ -w /dev/shm ]]; then
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=""
while [[ -z $ms_out ]] && ((++count<=10)); do
read ms_out < <(date +%s%3N)
done
}
fi
fi
init_() { #? Collect needed information and set options before startig main loop
local i