summaryrefslogtreecommitdiff
path: root/powerlevel9k.zsh-theme
diff options
context:
space:
mode:
Diffstat (limited to 'powerlevel9k.zsh-theme')
-rwxr-xr-xpowerlevel9k.zsh-theme51
1 files changed, 51 insertions, 0 deletions
diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme
index 5960dbe8..39454b59 100755
--- a/powerlevel9k.zsh-theme
+++ b/powerlevel9k.zsh-theme
@@ -578,6 +578,39 @@ prompt_custom() {
fi
}
+# Display the duration the command needed to run.
+prompt_command_execution_time() {
+ set_default POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD 3
+ set_default POWERLEVEL9K_COMMAND_EXECUTION_TIME_PRECISION 2
+
+ # Print time in human readable format
+ # For that use `strftime` and convert
+ # the duration (float) to an seconds
+ # (integer).
+ # See http://unix.stackexchange.com/a/89748
+ local humanReadableDuration
+ if (( _P9K_COMMAND_DURATION > 3600 )); then
+ humanReadableDuration=$(TZ=GMT; strftime '%H:%M:%S' $(( int(rint(_P9K_COMMAND_DURATION)) )))
+ elif (( _P9K_COMMAND_DURATION > 60 )); then
+ humanReadableDuration=$(TZ=GMT; strftime '%M:%S' $(( int(rint(_P9K_COMMAND_DURATION)) )))
+ else
+ # If the command executed in seconds, print as float.
+ # Convert to float
+ if [[ "${POWERLEVEL9K_COMMAND_EXECUTION_TIME_PRECISION}" == "0" ]]; then
+ # If user does not want microseconds, then we need to convert
+ # the duration to an integer.
+ typeset -i humanReadableDuration
+ else
+ typeset -F ${POWERLEVEL9K_COMMAND_EXECUTION_TIME_PRECISION} humanReadableDuration
+ fi
+ humanReadableDuration=$_P9K_COMMAND_DURATION
+ fi
+
+ if (( _P9K_COMMAND_DURATION >= POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD )); then
+ "$1_prompt_segment" "$0" "$2" "red" "226" "${humanReadableDuration}" 'EXECUTION_TIME_ICON'
+ fi
+}
+
# Dir: current working directory
set_default POWERLEVEL9K_DIR_PATH_SEPARATOR "/"
prompt_dir() {
@@ -1222,9 +1255,17 @@ build_right_prompt() {
done
}
+powerlevel9k_preexec() {
+ _P9K_TIMER_START=$EPOCHREALTIME
+}
+
powerlevel9k_prepare_prompts() {
RETVAL=$?
+ _P9K_COMMAND_DURATION=$((EPOCHREALTIME - _P9K_TIMER_START))
+ # Reset start time
+ _P9K_TIMER_START=99999999999
+
if [[ "$POWERLEVEL9K_PROMPT_ON_NEWLINE" == true ]]; then
PROMPT="$(print_icon 'MULTILINE_FIRST_PROMPT_PREFIX')%f%b%k$(build_left_prompt)
$(print_icon 'MULTILINE_SECOND_PROMPT_PREFIX')"
@@ -1253,6 +1294,9 @@ $(print_icon 'MULTILINE_SECOND_PROMPT_PREFIX')"
}
prompt_powerlevel9k_setup() {
+ # Disable false display of command execution time
+ _P9K_TIMER_START=99999999999
+
# Display a warning if the terminal does not support 256 colors
local term_colors
term_colors=$(echotc Co)
@@ -1297,11 +1341,18 @@ prompt_powerlevel9k_setup() {
powerlevel9k_vcs_init
fi
+ # initialize timing functions
+ zmodload zsh/datetime
+
+ # Initialize math functions
+ zmodload zsh/mathfunc
+
# initialize hooks
autoload -Uz add-zsh-hook
# prepare prompts
add-zsh-hook precmd powerlevel9k_prepare_prompts
+ add-zsh-hook preexec powerlevel9k_preexec
}
prompt_powerlevel9k_setup "$@"