timer: threshold to show timers only for time-consuming commands (#8151)
Diff
1diff --git a/plugins/timer/README.md b/plugins/timer/README.md
2index 321307e59d4d6c91f4f181de0d0252f4d7fa6f4b..30b0bd00e355d6c58b7e87d0ec0f1fcf7c8b5479 100644
3--- a/plugins/timer/README.md
4+++ b/plugins/timer/README.md
5@@ -3,6 +3,7 @@ This plugin allows to display command's execution time in a very nonintrusive wa
6 Timer can be tuned by these two variables:
7 * `TIMER_PRECISION` allows to control number of decimal places (default `1`)
8 * `TIMER_FORMAT` allows to adjust display format (default `'/%d'`)
9+* `TIMER_THRESHOLD` allows to set the minimum execution time that causes the timer to be shown (default `0`)
1011 Sample session:
1213diff --git a/plugins/timer/timer.plugin.zsh b/plugins/timer/timer.plugin.zsh
14index 728377c5cc5cd99905dd68d8d452182879981ee5..1be7516a3a82b4424d5007b5095ae154aeaf9f17 100644
15--- a/plugins/timer/timer.plugin.zsh
16+++ b/plugins/timer/timer.plugin.zsh
17@@ -19,9 +19,11 @@ __timer_display_timer_precmd() {
18 local cmd_end_time=$(__timer_current_time)
19 local tdiff=$((cmd_end_time - __timer_cmd_start_time))
20 unset __timer_cmd_start_time
21- local tdiffstr=$(__timer_format_duration ${tdiff})
22- local cols=$((COLUMNS - ${#tdiffstr} - 1))
23- echo -e "\033[1A\033[${cols}C ${tdiffstr}"
24+ if [[ -z "${TIMER_THRESHOLD}" || ${tdiff} -ge "${TIMER_THRESHOLD}" ]]; then
25+ local tdiffstr=$(__timer_format_duration ${tdiff})
26+ local cols=$((COLUMNS - ${#tdiffstr} - 1))
27+ echo -e "\033[1A\033[${cols}C ${tdiffstr}"
28+ fi
29 fi
30 }
31