1
0
Fork 0
mirror of https://github.com/romkatv/powerlevel10k.git synced 2024-12-18 21:41:57 +00:00

add P9K_COMMAND_DURATION_SECONDS and POWERLEVEL9K_COMMAND_EXECUTION_TIME_DISABLE_FORMATTING

This commit is contained in:
romkatv 2019-07-16 20:35:18 +02:00
parent 36fa083841
commit ccfc462faf

View file

@ -888,12 +888,15 @@ prompt_custom() {
################################################################ ################################################################
# Display the duration the command needed to run. # Display the duration the command needed to run.
typeset -gF _P9K_COMMAND_DURATION
set_default -i POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD 3 set_default -i POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD 3
set_default -i POWERLEVEL9K_COMMAND_EXECUTION_TIME_PRECISION 2 set_default -i POWERLEVEL9K_COMMAND_EXECUTION_TIME_PRECISION 2
set_default POWERLEVEL9K_COMMAND_EXECUTION_TIME_DISABLE_FORMATTING false
prompt_command_execution_time() { prompt_command_execution_time() {
(( _P9K_COMMAND_DURATION < POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD )) && return (( $+P9K_COMMAND_DURATION_SECONDS && P9K_COMMAND_DURATION_SECONDS >= POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD )) || return
if [[ $POWERLEVEL9K_COMMAND_EXECUTION_TIME_DISABLE_FORMATTING == true ]]; then
local text=''
else
if (( _P9K_COMMAND_DURATION < 60 )); then if (( _P9K_COMMAND_DURATION < 60 )); then
if [[ $POWERLEVEL9K_COMMAND_EXECUTION_TIME_PRECISION == 0 ]]; then if [[ $POWERLEVEL9K_COMMAND_EXECUTION_TIME_PRECISION == 0 ]]; then
local -i sec=$((_P9K_COMMAND_DURATION + 0.5)) local -i sec=$((_P9K_COMMAND_DURATION + 0.5))
@ -913,6 +916,7 @@ prompt_command_execution_time() {
fi fi
fi fi
fi fi
fi
"$1_prompt_segment" "$0" "$2" "red" "yellow1" 'EXECUTION_TIME_ICON' 0 '' $text "$1_prompt_segment" "$0" "$2" "red" "yellow1" 'EXECUTION_TIME_ICON' 0 '' $text
} }
@ -2457,8 +2461,6 @@ prompt_java_version() {
set_default -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS context dir vcs set_default -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS context dir vcs
set_default -a POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS status root_indicator background_jobs history time set_default -a POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS status root_indicator background_jobs history time
typeset -gF _P9K_TIMER_START
powerlevel9k_preexec() { powerlevel9k_preexec() {
if (( _P9K_EMULATE_ZERO_RPROMPT_INDENT )); then if (( _P9K_EMULATE_ZERO_RPROMPT_INDENT )); then
if [[ -n $_P9K_REAL_ZLE_RPROMPT_INDENT ]]; then if [[ -n $_P9K_REAL_ZLE_RPROMPT_INDENT ]]; then
@ -2467,7 +2469,7 @@ powerlevel9k_preexec() {
unset ZLE_RPROMPT_INDENT unset ZLE_RPROMPT_INDENT
fi fi
fi fi
_P9K_TIMER_START=$EPOCHREALTIME typeset -gF _P9K_TIMER_START=EPOCHREALTIME
} }
typeset -g _P9K_PROMPT typeset -g _P9K_PROMPT
@ -2559,8 +2561,12 @@ powerlevel9k_refresh_prompt_inplace() {
powerlevel9k_prepare_prompts() { powerlevel9k_prepare_prompts() {
_P9K_EXIT_CODE=$? _P9K_EXIT_CODE=$?
_P9K_PIPE_EXIT_CODES=( "$pipestatus[@]" ) _P9K_PIPE_EXIT_CODES=( "$pipestatus[@]" )
_P9K_COMMAND_DURATION=$((EPOCHREALTIME - _P9K_TIMER_START)) if (( $+_P9K_TIMER_START )); then
_P9K_TIMER_START=1e10 P9K_COMMAND_DURATION_SECONDS=$((EPOCHREALTIME - _P9K_TIMER_START))
unset _P9K_TIMER_START
else
unset P9K_COMMAND_DURATION_SECONDS
fi
_P9K_REGION_ACTIVE=0 _P9K_REGION_ACTIVE=0
unsetopt localoptions unsetopt localoptions
@ -3168,7 +3174,7 @@ prompt_powerlevel9k_setup() {
add-zsh-hook precmd powerlevel9k_prepare_prompts add-zsh-hook precmd powerlevel9k_prepare_prompts
add-zsh-hook preexec powerlevel9k_preexec add-zsh-hook preexec powerlevel9k_preexec
_P9K_TIMER_START=1e10 unset _P9K_TIMER_START
_P9K_ENABLED=1 _P9K_ENABLED=1
} }