From 85a48caaffa7bd716b2a23b707803c3f3f26b96e Mon Sep 17 00:00:00 2001 From: Stuart Axon Date: Wed, 2 Oct 2019 12:01:14 +0100 Subject: [PATCH 1/4] Speed up last_status by avoiding wc -l MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On my system using native bash functions instead of wc -l speeds up the last_status by about 0.2 seconds. This may be because windows pipes are slow or some issue with wc. Before: ```  master last_status: 0.463 user_info: 0.066 cwd: 0.071 scm: 2.549 ``` After: ``` last_status: 0.228 user_info: 0.079 cwd: 0.073 scm: 2.714 ``` Performance numbers aren't exact as they vary a bit, but you can see a bit difference in the runtime for last_status. --- theme.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/theme.bash b/theme.bash index 98ec135..3df912d 100644 --- a/theme.bash +++ b/theme.bash @@ -197,7 +197,7 @@ function __powerline_last_status_prompt { local symbols=() [[ $last_status -ne 0 ]] && symbols+="$(__color ${STATUS_PROMPT_ERROR_COLOR})${STATUS_PROMPT_ERROR}" [[ $UID -eq 0 ]] && symbols+="$(__color ${STATUS_PROMPT_ROOT_COLOR})${STATUS_PROMPT_ROOT}" - [[ $(jobs -l | wc -l) -gt 0 ]] && symbols+="$(__color ${STATUS_PROMPT_JOBS_COLOR})${STATUS_PROMPT_JOBS}" + [[ ! -z $(read -r line <<< $(jobs -l); echo $line) ]] && symbols+="$(__color ${STATUS_PROMPT_JOBS_COLOR})${STATUS_PROMPT_JOBS}" [[ -n "$symbols" ]] && echo "$symbols|${STATUS_PROMPT_COLOR}" } From 8e05984b56bcfcef58608d586e01e5d5c41516b2 Mon Sep 17 00:00:00 2001 From: Stuart Axon Date: Wed, 2 Oct 2019 12:17:02 +0100 Subject: [PATCH 2/4] Update theme.bash Last status: get read to bail out earlier. Get jobs command to output less by only outputting the pids of stopped jobs. --- theme.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/theme.bash b/theme.bash index 3df912d..dcf5d5f 100644 --- a/theme.bash +++ b/theme.bash @@ -197,7 +197,7 @@ function __powerline_last_status_prompt { local symbols=() [[ $last_status -ne 0 ]] && symbols+="$(__color ${STATUS_PROMPT_ERROR_COLOR})${STATUS_PROMPT_ERROR}" [[ $UID -eq 0 ]] && symbols+="$(__color ${STATUS_PROMPT_ROOT_COLOR})${STATUS_PROMPT_ROOT}" - [[ ! -z $(read -r line <<< $(jobs -l); echo $line) ]] && symbols+="$(__color ${STATUS_PROMPT_JOBS_COLOR})${STATUS_PROMPT_JOBS}" + [[ ! -z $(read -r -n1 stopped_jobs <<< $(jobs -sp); echo $stopped_jobs) ]] && symbols+="$(__color ${STATUS_PROMPT_JOBS_COLOR})${STATUS_PROMPT_JOBS}" [[ -n "$symbols" ]] && echo "$symbols|${STATUS_PROMPT_COLOR}" } From 01332664d6db477c5499cd16a47a965a2ad61be5 Mon Sep 17 00:00:00 2001 From: Stuart Axon Date: Wed, 2 Oct 2019 12:41:06 +0100 Subject: [PATCH 3/4] Update theme.bash Speed up last_status further by not using $() around job collection. --- theme.bash | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/theme.bash b/theme.bash index dcf5d5f..8a88966 100644 --- a/theme.bash +++ b/theme.bash @@ -194,10 +194,12 @@ function __powerline_left_segment { } function __powerline_last_status_prompt { - local symbols=() + local symbols=() + local stopped_jobs + jobs -sp | read -n1 stopped_jobs [[ $last_status -ne 0 ]] && symbols+="$(__color ${STATUS_PROMPT_ERROR_COLOR})${STATUS_PROMPT_ERROR}" [[ $UID -eq 0 ]] && symbols+="$(__color ${STATUS_PROMPT_ROOT_COLOR})${STATUS_PROMPT_ROOT}" - [[ ! -z $(read -r -n1 stopped_jobs <<< $(jobs -sp); echo $stopped_jobs) ]] && symbols+="$(__color ${STATUS_PROMPT_JOBS_COLOR})${STATUS_PROMPT_JOBS}" + [[ ! -z "$stopped_jobs" ]] && symbols+="$(__color ${STATUS_PROMPT_JOBS_COLOR})${STATUS_PROMPT_JOBS}" [[ -n "$symbols" ]] && echo "$symbols|${STATUS_PROMPT_COLOR}" } From b10124da68c3cfc3ef52012523c255e2751f36b7 Mon Sep 17 00:00:00 2001 From: Stuart Axon Date: Wed, 2 Oct 2019 13:26:27 +0100 Subject: [PATCH 4/4] Update theme.bash Small adjustment to unbreak this :) --- theme.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/theme.bash b/theme.bash index 8a88966..dbea07e 100644 --- a/theme.bash +++ b/theme.bash @@ -196,7 +196,7 @@ function __powerline_left_segment { function __powerline_last_status_prompt { local symbols=() local stopped_jobs - jobs -sp | read -n1 stopped_jobs + read -N1 stopped_jobs < <(jobs -sp) [[ $last_status -ne 0 ]] && symbols+="$(__color ${STATUS_PROMPT_ERROR_COLOR})${STATUS_PROMPT_ERROR}" [[ $UID -eq 0 ]] && symbols+="$(__color ${STATUS_PROMPT_ROOT_COLOR})${STATUS_PROMPT_ROOT}" [[ ! -z "$stopped_jobs" ]] && symbols+="$(__color ${STATUS_PROMPT_JOBS_COLOR})${STATUS_PROMPT_JOBS}"