Humanize the execution time. Fixes #46
This commit is contained in:
17
pure.zsh
17
pure.zsh
@@ -16,6 +16,21 @@
|
|||||||
# %m => shortname host
|
# %m => shortname host
|
||||||
# %(?..) => prompt conditional - %(condition.true.false)
|
# %(?..) => prompt conditional - %(condition.true.false)
|
||||||
|
|
||||||
|
|
||||||
|
# turns seconds into human readable time
|
||||||
|
# 165392 => 1d 21h 56h 32s
|
||||||
|
prompt_pure_human_time() {
|
||||||
|
local tmp=$1
|
||||||
|
local days=$(( tmp / 60 / 60 / 24 ))
|
||||||
|
local hours=$(( tmp / 60 / 60 % 24 ))
|
||||||
|
local minutes=$(( tmp / 60 % 60 ))
|
||||||
|
local seconds=$(( tmp % 60 ))
|
||||||
|
(( $days > 0 )) && echo -n "${days}d "
|
||||||
|
(( $hours > 0 )) && echo -n "${hours}h "
|
||||||
|
(( $minutes > 0 )) && echo -n "${minutes}h "
|
||||||
|
echo "${seconds}s"
|
||||||
|
}
|
||||||
|
|
||||||
# fastest possible way to check if repo is dirty
|
# fastest possible way to check if repo is dirty
|
||||||
prompt_pure_git_dirty() {
|
prompt_pure_git_dirty() {
|
||||||
# check if we're in a git repo
|
# check if we're in a git repo
|
||||||
@@ -31,7 +46,7 @@ prompt_pure_cmd_exec_time() {
|
|||||||
local stop=$(date +%s)
|
local stop=$(date +%s)
|
||||||
local start=${cmd_timestamp:-$stop}
|
local start=${cmd_timestamp:-$stop}
|
||||||
integer elapsed=$stop-$start
|
integer elapsed=$stop-$start
|
||||||
(($elapsed > ${PURE_CMD_MAX_EXEC_TIME:=5})) && echo ${elapsed}s
|
(($elapsed > ${PURE_CMD_MAX_EXEC_TIME:=5})) && prompt_pure_human_time $elapsed
|
||||||
}
|
}
|
||||||
|
|
||||||
prompt_pure_preexec() {
|
prompt_pure_preexec() {
|
||||||
|
|||||||
Reference in New Issue
Block a user