-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bug: Use en_US when fetching EPOCHREALTIME
Isolates fetching of EPOCHREALTIME to a function which sets LC_ALL=en_US.UTF-8. This ensures that the value is in decimal format, regardless of runtime locale. bug: Hide duration when no command executed
- Loading branch information
1 parent
1c9cfd0
commit 7c7e4f9
Showing
3 changed files
with
23 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,12 +2,24 @@ | |
# | ||
# Functions for measuring and reporting how long a command takes to run. | ||
|
||
: "${COMMAND_DURATION_START_SECONDS:=${EPOCHREALTIME:-$SECONDS}}" | ||
# Get shell duration in decimal format regardless of runtime locale. | ||
# Notice: This function runs as a sub-shell - notice '(' vs '{'. | ||
function _shell_duration_en() ( | ||
# DFARREL You would think LC_NUMERIC would do it, but not working in my local | ||
LC_ALL='en_US.UTF-8' | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
akinomyoga
Contributor
|
||
printf "%s" "${EPOCHREALTIME:-$SECONDS}" | ||
) | ||
|
||
: "${COMMAND_DURATION_START_SECONDS:=$(_shell_duration_en)}" | ||
: "${COMMAND_DURATION_ICON:=🕘}" | ||
: "${COMMAND_DURATION_MIN_SECONDS:=1}" | ||
|
||
function _command_duration_pre_exec() { | ||
COMMAND_DURATION_START_SECONDS="${EPOCHREALTIME:-$SECONDS}" | ||
COMMAND_DURATION_START_SECONDS="$(_shell_duration_en)" | ||
} | ||
|
||
function _command_duration_pre_cmd() { | ||
COMMAND_DURATION_START_SECONDS="" | ||
} | ||
|
||
function _dynamic_clock_icon { | ||
|
@@ -20,13 +32,15 @@ function _dynamic_clock_icon { | |
|
||
function _command_duration() { | ||
[[ -n "${BASH_IT_COMMAND_DURATION:-}" ]] || return | ||
[[ -n "${COMMAND_DURATION_START_SECONDS:-}" ]] || return | ||
|
||
local command_duration=0 command_start="${COMMAND_DURATION_START_SECONDS:-0}" | ||
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 current_time | ||
current_time="$(_shell_duration_en)" | ||
local -i current_time_seconds="${current_time%.*}" | ||
local -i current_time_deciseconds="$((10#${current_time##*.}))" | ||
current_time_deciseconds="${current_time_deciseconds:0:1}" | ||
|
@@ -59,3 +73,4 @@ function _command_duration() { | |
} | ||
|
||
_bash_it_library_finalize_hook+=("safe_append_preexec '_command_duration_pre_exec'") | ||
_bash_it_library_finalize_hook+=("safe_append_prompt_command '_command_duration_pre_cmd'") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
On a very recently installed Raspberry Pi I'm finding this sub-shell call causes an error for every new terminal command.
-bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8): No such file or directory
Not optimal. Commenting it out the LC_ALL here makes that error go away with no obvious detrimental effects.
Seems like requiring en_US.UTF-8 to exist isn't a good requirement.. but if it is required then perhaps another check is needed to verify the system you are on has en_US.UTF-8.
locale
on a recently installed Raspberry Pi is:locale -a
Reconfiguring my pi to use
en_US.UTF-8
is possible:sudo raspi-config nonint do_change_locale en_US.UTF-8
But I feel like that is possibly cheating for all those non en_US people out there that don't want to switch to that. It does solve the problem though.