def fmt_ms [ms: int] { $'($ms)ms' | into duration }\n# If you prefer h & s than hr & sec\ndef fmt_ms [ms: int] { $'($ms)ms' | into duration | into string | str replace hr h | str replace sec s }-
|
I use this function in my ZSH config to format the execution time of a command in the prompt, using NuShell I already get the execution time from function fmt_ms() {
local total_ms=$1
local ms=$((total_ms % 1000))
local total_seconds=$((total_ms / 1000))
local seconds=$((total_seconds % 60))
local total_minutes=$((total_seconds / 60))
local minutes=$((total_minutes % 60))
local hours=$((total_minutes / 60))
local formatted=""
[[ $hours -gt 0 ]] && formatted+="${hours}h "
[[ $minutes -gt 0 ]] && formatted+="${minutes}min "
[[ $seconds -gt 0 ]] && formatted+="${seconds}s "
echo "$formatted"
} |
Beta Was this translation helpful? Give feedback.
-
def fmt_ms [ms: int] { $'($ms)ms' | into duration }
# If you prefer h & s than hr & sec
def fmt_ms [ms: int] { $'($ms)ms' | into duration | into string | str replace hr h | str replace sec s } |
Beta Was this translation helpful? Give feedback.
def fmt_ms [ms: int] { $'($ms)ms' | into duration } # If you prefer h & s than hr & sec def fmt_ms [ms: int] { $'($ms)ms' | into duration | into string | str replace hr h | str replace sec s }