Humanize the execution time. Fixes #46

This commit is contained in:
Sindre Sorhus
2013-12-21 23:33:32 +01:00
parent 1e141ab879
commit d99a94f34e

View File

@@ -16,6 +16,21 @@
# %m => shortname host
# %(?..) => 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
prompt_pure_git_dirty() {
# check if we're in a git repo
@@ -31,7 +46,7 @@ prompt_pure_cmd_exec_time() {
local stop=$(date +%s)
local start=${cmd_timestamp:-$stop}
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() {