Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
0119368
Delete preexec vendor
BarbUk Feb 3, 2026
027b7ae
Squashed 'vendor/github.com/rcaloras/bash-preexec/' content from comm…
BarbUk Feb 3, 2026
b509d72
Add "preexec" from "https://github.com/rcaloras/bash-preexec@0.6.0"
BarbUk Feb 3, 2026
7ab0074
Update precommit
BarbUk Feb 3, 2026
ee821b3
Rework command duration plugin to handle locale with . or , and remov…
BarbUk Feb 3, 2026
f630441
Sh format
BarbUk Feb 3, 2026
b42c3ac
Revert "Update precommit"
BarbUk Feb 3, 2026
1857412
Fix cmd-returned-notify.plugin.bash
BarbUk Feb 3, 2026
83f11a8
Fix _shell_duration_en function call, restore original variable names
BarbUk Feb 3, 2026
64ec7e7
With recent version of bash preexec set PROMPT_COMMAND as an array
BarbUk Feb 3, 2026
4c60358
But leave test for old macos version of bash
BarbUk Feb 3, 2026
5ae5522
New version of preexec add a :
BarbUk Feb 3, 2026
f689001
Fix preexec bats tests shellcheck errors
BarbUk Feb 3, 2026
d65288f
, and . are not the only possibilities of decimal_point
BarbUk Feb 3, 2026
2339683
Ignore warning for vendors bats test files
BarbUk Feb 3, 2026
3e3ddf3
Add default for COMMAND_DURATION_START_SECONDS
BarbUk Feb 3, 2026
7373708
Fix shellcheck SC1091 for vendor bats tests
BarbUk Feb 3, 2026
9e88c2a
Ignore last shellcheck error in vendor bats tests
BarbUk Feb 3, 2026
1fb6e65
Add more information about the reason of this change
BarbUk Feb 10, 2026
f775bbd
Get the current time from command_duration lib function
BarbUk Feb 10, 2026
53de05d
Work with microseconds, truncate the output to display
BarbUk Feb 10, 2026
4d86661
Only calculate and display microseconds if precision > 0
BarbUk Feb 10, 2026
ee1c783
Add documentation about COMMAND_DURATION_PRECISION
BarbUk Feb 10, 2026
42b8086
Handle case with leading 0 in microseconds
BarbUk Feb 10, 2026
5ef3b70
Handle case with leading 0 in microseconds
BarbUk Feb 10, 2026
9e5f7ce
No quote for integer local var
BarbUk Feb 10, 2026
c0f2a5d
Add tests
BarbUk Feb 10, 2026
964e9bc
Disable shellcheck false positive for bats tests
BarbUk Feb 10, 2026
67cb1b2
local -> locale
BarbUk Feb 11, 2026
3c39331
Rephrase
BarbUk Feb 11, 2026
275c8d3
overide -> override
BarbUk Feb 11, 2026
910dbed
Fix phrasing
BarbUk Feb 11, 2026
43f1bd4
Add tests when EPOCHREALTIME is not available
BarbUk Feb 11, 2026
b848e5b
Uses string instead of int
BarbUk Feb 11, 2026
71a8a71
Reintroduce paste documentation to keep context about this change
BarbUk Feb 11, 2026
dd80054
Remove unused code branch
BarbUk Feb 12, 2026
ed314d5
Add test with precision 0 and microseconds time
BarbUk Feb 12, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ minimum_pre_commit_version: 1.18.1
exclude: "docs/_build/|vendor/"
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
rev: v6.0.0
hooks:
- id: trailing-whitespace
exclude: ".(md|rst)$"
Expand All @@ -15,14 +15,14 @@ repos:
- id: mixed-line-ending
- id: check-added-large-files
- repo: https://github.com/jumanjihouse/pre-commit-hooks
rev: 2.1.5
rev: 3.0.0
hooks:
- id: git-check # Configure in .gitattributes
- id: shellcheck
files: "\\.(bash)$"
- id: shfmt
- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.1.7
rev: v1.5.6
hooks:
# - id: forbid-crlf
- id: remove-crlf
Expand Down
69 changes: 37 additions & 32 deletions lib/command_duration.bash
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,17 @@
# Functions for measuring and reporting how long a command takes to run.

# 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.
# Note: LC_ALL='en_US.UTF-8' has been used to enforce the decimal point to be
# a period, but the specific locale 'en_US.UTF-8' is not ensured to exist in
# the system. One should instead use the locale 'C', which is ensured by the
# C and POSIX standards.
Comment thread
BarbUk marked this conversation as resolved.
local LC_ALL=C
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="$(_shell_duration_en)"
if [[ -n "${EPOCHREALTIME:-}" ]]; then
COMMAND_DURATION_START_SECONDS="${EPOCHREALTIME//,/.}"
else
COMMAND_DURATION_START_SECONDS="$SECONDS"
fi
}

: "${COMMAND_DURATION_ICON:=🕘}"
: "${COMMAND_DURATION_MIN_SECONDS:=1}"

function _command_duration_pre_cmd() {
COMMAND_DURATION_START_SECONDS=""
}
Expand All @@ -38,29 +30,42 @@ 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
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}"
if [[ -n "${EPOCHREALTIME:-}" ]]; then
current_time="${EPOCHREALTIME//,/.}"
else
current_time="$SECONDS"
fi

local -i command_duration=0
local -i minutes=0 seconds=0 deciseconds=0

local -i start_s=${COMMAND_DURATION_START_SECONDS%.*}
local -i curr_s=${current_time%.*}

# Calculate seconds difference
command_duration=$((curr_s - start_s))

if [[ "${command_start_seconds:-0}" -gt 0 ]]; then
# seconds
command_duration="$((current_time_seconds - command_start_seconds))"
# Calculate deciseconds if both timestamps have fractional parts
if [[ "$COMMAND_DURATION_START_SECONDS" == *.* ]] && [[ "$current_time" == *.* ]]; then
local start_fs="${COMMAND_DURATION_START_SECONDS#*.}"
local curr_fs="${current_time#*.}"

if ((current_time_deciseconds >= command_start_deciseconds)); then
deciseconds="$((current_time_deciseconds - command_start_deciseconds))"
# Take first digit for deciseconds
local -i start_ds="${start_fs:0:1}"
local -i curr_ds="${curr_fs:0:1}"

if ((curr_ds >= start_ds)); then
deciseconds=$((curr_ds - start_ds))
else
((command_duration -= 1))
deciseconds="$((10 - (command_start_deciseconds - current_time_deciseconds)))"
deciseconds=$((10 + curr_ds - start_ds))
fi
else
fi

if ((command_duration < 0)); then
command_duration=0
deciseconds=0
fi

if ((command_duration >= COMMAND_DURATION_MIN_SECONDS)); then
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 0 additions & 20 deletions vendor/github.com/rcaloras/bash-preexec/.travis.yml

This file was deleted.

19 changes: 14 additions & 5 deletions vendor/github.com/rcaloras/bash-preexec/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading