2
2
#
3
3
# Functions for measuring and reporting how long a command takes to run.
4
4
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)} "
6
14
: " ${COMMAND_DURATION_ICON:= 🕘} "
7
15
: " ${COMMAND_DURATION_MIN_SECONDS:= 1} "
8
16
9
17
function _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=" "
11
23
}
12
24
13
25
function _dynamic_clock_icon {
@@ -20,13 +32,15 @@ function _dynamic_clock_icon {
20
32
21
33
function _command_duration() {
22
34
[[ -n " ${BASH_IT_COMMAND_DURATION:- } " ]] || return
35
+ [[ -n " ${COMMAND_DURATION_START_SECONDS:- } " ]] || return
23
36
24
37
local command_duration=0 command_start=" ${COMMAND_DURATION_START_SECONDS:- 0} "
25
38
local -i minutes=0 seconds=0 deciseconds=0
26
39
local -i command_start_seconds=" ${command_start% .* } "
27
40
local -i command_start_deciseconds=$(( 10 #${command_start##* .} ))
28
41
command_start_deciseconds=" ${command_start_deciseconds: 0: 1} "
29
- local current_time=" ${EPOCHREALTIME:- $SECONDS } "
42
+ local current_time
43
+ current_time=" $( _shell_duration_en) "
30
44
local -i current_time_seconds=" ${current_time% .* } "
31
45
local -i current_time_deciseconds=" $(( 10 #${current_time##* .} )) "
32
46
current_time_deciseconds=" ${current_time_deciseconds: 0: 1} "
@@ -59,3 +73,4 @@ function _command_duration() {
59
73
}
60
74
61
75
_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