Merge pull request #2119 from BarbUk/fix/command_duration_precision

Fix/command duration precision
pull/2138/head
Noah Gorny 2022-03-14 11:59:27 +02:00 committed by GitHub
commit d1b831a92d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 2 deletions

View File

@ -25,9 +25,11 @@ function _command_duration() {
local -i minutes=0 seconds=0 deciseconds=0
local -i command_start_seconds="${command_start%.*}"
local -i command_start_deciseconds=$((10#${command_start##*.}))
command_start_deciseconds="${command_start_deciseconds:0:1}"
local current_time="${EPOCHREALTIME:-$SECONDS}"
local -i current_time_seconds="${current_time%.*}"
local -i current_time_deciseconds="$((10#${current_time##*.}))"
current_time_deciseconds="${current_time_deciseconds:0:1}"
if [[ "${command_start_seconds:-0}" -gt 0 ]]; then
# seconds
@ -50,9 +52,9 @@ function _command_duration() {
_dynamic_clock_icon "${command_duration}"
if ((minutes > 0)); then
printf "%s%s%dm %ds" "${COMMAND_DURATION_ICON:-}" "${COMMAND_DURATION_COLOR:-}" "$minutes" "$seconds"
printf "%s %s%dm %ds" "${COMMAND_DURATION_ICON:-}" "${COMMAND_DURATION_COLOR:-}" "$minutes" "$seconds"
elif ((seconds >= COMMAND_DURATION_MIN_SECONDS)); then
printf "%s%s%d.%01ds" "${COMMAND_DURATION_ICON:-}" "${COMMAND_DURATION_COLOR:-}" "$seconds" "$deciseconds"
printf "%s %s%d.%01ds" "${COMMAND_DURATION_ICON:-}" "${COMMAND_DURATION_COLOR:-}" "$seconds" "$deciseconds"
fi
}