22#
33# Functions for measuring and reporting how long a command takes to run.
44
5- : " ${COMMAND_DURATION_START_SECONDS:= ${EPOCHREALTIME:- $SECONDS } } "
5+ # Get shell duration in decimal format regardless of runtime locale.
6+ # Notice: This function runs as a sub-shell - notice '(' vs '{'.
7+ function _shell_duration_en() (
8+ # DFARREL You would think LC_NUMERIC would do it, but not working in my local
9+ LC_ALL=' en_US.UTF-8'
10+ printf " %s" " ${EPOCHREALTIME:- $SECONDS } "
11+ )
12+
13+ : " ${COMMAND_DURATION_START_SECONDS:= $(_shell_duration_en)} "
614: " ${COMMAND_DURATION_ICON:= 🕘} "
715: " ${COMMAND_DURATION_MIN_SECONDS:= 1} "
816
917function _command_duration_pre_exec() {
10- COMMAND_DURATION_START_SECONDS=" ${EPOCHREALTIME:- $SECONDS } "
18+ COMMAND_DURATION_START_SECONDS=" $( _shell_duration_en) "
19+ }
20+
21+ function _command_duration_pre_cmd() {
22+ COMMAND_DURATION_START_SECONDS=" "
1123}
1224
1325function _dynamic_clock_icon {
@@ -20,13 +32,15 @@ function _dynamic_clock_icon {
2032
2133function _command_duration() {
2234 [[ -n " ${BASH_IT_COMMAND_DURATION:- } " ]] || return
35+ [[ -n " ${COMMAND_DURATION_START_SECONDS:- } " ]] || return
2336
2437 local command_duration=0 command_start=" ${COMMAND_DURATION_START_SECONDS:- 0} "
2538 local -i minutes=0 seconds=0 deciseconds=0
2639 local -i command_start_seconds=" ${command_start% .* } "
2740 local -i command_start_deciseconds=$(( 10 #${command_start##* .} ))
2841 command_start_deciseconds=" ${command_start_deciseconds: 0: 1} "
29- local current_time=" ${EPOCHREALTIME:- $SECONDS } "
42+ local current_time
43+ current_time=" $( _shell_duration_en) "
3044 local -i current_time_seconds=" ${current_time% .* } "
3145 local -i current_time_deciseconds=" $(( 10 #${current_time##* .} )) "
3246 current_time_deciseconds=" ${current_time_deciseconds: 0: 1} "
@@ -59,3 +73,4 @@ function _command_duration() {
5973}
6074
6175_bash_it_library_finalize_hook+=(" safe_append_preexec '_command_duration_pre_exec'" )
76+ _bash_it_library_finalize_hook+=(" safe_append_prompt_command '_command_duration_pre_cmd'" )
0 commit comments