From 2ef9e99d42cf1623d94ddcbb6d0c8a91fb7b4970 Mon Sep 17 00:00:00 2001 From: Yongqian Li Date: Tue, 3 May 2016 16:40:42 -0700 Subject: [PATCH] Display exec time as something like 2d3h31m5s instead of 185465s --- bullet-train.zsh-theme | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/bullet-train.zsh-theme b/bullet-train.zsh-theme index 8314623..8441c58 100644 --- a/bullet-train.zsh-theme +++ b/bullet-train.zsh-theme @@ -354,6 +354,19 @@ prompt_context() { [[ -n "$_context" ]] && prompt_segment $BULLETTRAIN_CONTEXT_BG $BULLETTRAIN_CONTEXT_FG "$_context" } +# Based on http://stackoverflow.com/a/32164707/3859566 +function displaytime { + local T=$1 + local D=$((T/60/60/24)) + local H=$((T/60/60%24)) + local M=$((T/60%60)) + local S=$((T%60)) + [[ $D > 0 ]] && printf '%dd' $D + [[ $H > 0 ]] && printf '%dh' $H + [[ $M > 0 ]] && printf '%dm' $M + printf '%ds' $S +} + # Prompt previous command execution time preexec() { cmd_timestamp=`date +%s` @@ -371,7 +384,7 @@ precmd() { prompt_cmd_exec_time() { [[ $BULLETTRAIN_EXEC_TIME_SHOW == false ]] && return - [ $BULLETTRAIN_last_exec_duration -gt $BULLETTRAIN_EXEC_TIME_ELAPSED ] && prompt_segment $BULLETTRAIN_EXEC_TIME_BG $BULLETTRAIN_EXEC_TIME_FG "${BULLETTRAIN_last_exec_duration}s" + [ $BULLETTRAIN_last_exec_duration -gt $BULLETTRAIN_EXEC_TIME_ELAPSED ] && prompt_segment $BULLETTRAIN_EXEC_TIME_BG $BULLETTRAIN_EXEC_TIME_FG "$(displaytime $BULLETTRAIN_last_exec_duration)" } # Custom