From 13c7b698e52f7c7b2ffe991a591cab74d30b1977 Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Thu, 19 Dec 2024 05:33:20 +0900 Subject: [PATCH] perf(plugins/progress): cache the result of "clear_line" --- plugins/progress/progress.plugin.sh | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/plugins/progress/progress.plugin.sh b/plugins/progress/progress.plugin.sh index 7a4b88535..bc11fce9d 100644 --- a/plugins/progress/progress.plugin.sh +++ b/plugins/progress/progress.plugin.sh @@ -20,6 +20,8 @@ # Global variable to store progress value _omb_plugin_progress_value=0 +_omb_plugin_progress_clear_line= + # # Description : delay executing script # @@ -56,10 +58,13 @@ function progress { fi # Get a clear line escape sequence - local clear_line - clear_line=$(tput el 2>/dev/null || tput ce 2>/dev/null) + local clear_line=$_omb_plugin_progress_clear_line if [[ ! $clear_line ]]; then - clear_line=$'\e[K' + clear_line=$(tput el 2>/dev/null || tput ce 2>/dev/null) + if [[ ! $clear_line ]]; then + clear_line=$'\e[K' + fi + _omb_plugin_progress_clear_line=$clear_line fi if ((_omb_plugin_progress_value <= 0 && value >= 0)); then printf "%s[............................] (0%%) %s\r" "$clear_line" "$message"; delay; fi