From 09e8c25b644315f3b3499776884d0c6f6c5cc863 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Fri, 4 Mar 2022 12:39:58 -0800 Subject: [PATCH] lib/command_duration: dynamic clock hand Calculate the position (from 1 to 12) of the hour hand on the clock emoji used for the _command_duration string. Expressly handle COMMAND_DURATION_COLOR as blank when undefined. --- themes/command_duration.theme.bash | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/themes/command_duration.theme.bash b/themes/command_duration.theme.bash index c7fb6655..c0772d2d 100644 --- a/themes/command_duration.theme.bash +++ b/themes/command_duration.theme.bash @@ -9,7 +9,7 @@ fi COMMAND_DURATION_START_TIME= -COMMAND_DURATION_ICON=${COMMAND_DURATION_ICON:-'  '} +COMMAND_DURATION_ICON=${COMMAND_DURATION_ICON:-'  '} 🕘 COMMAND_DURATION_MIN_SECONDS=${COMMAND_DURATION_MIN_SECONDS:-'1'} _command_duration_pre_exec() { @@ -18,6 +18,11 @@ _command_duration_pre_exec() { COMMAND_DURATION_START_TIME="$(date "+%s").${command_nano_now}" } +function _dynamic_clock_icon { + local -i clock_hand=$(((${1:-${SECONDS}} % 12) + 90)) + printf -v 'COMMAND_DURATION_ICON' '%b' "\xf0\x9f\x95\x$clock_hand" +} + _command_duration() { local command_duration command_start current_time local minutes seconds deciseconds @@ -54,10 +59,11 @@ _command_duration() { seconds=$((command_duration % 60)) fi + _dynamic_clock_icon 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 }