summaryrefslogtreecommitdiff
path: root/themes
diff options
context:
space:
mode:
authorMarc Cornellà <hello@mcornella.com>2022-02-07 17:44:05 +0100
committerMarc Cornellà <hello@mcornella.com>2022-02-07 17:55:16 +0100
commit74a3db75e46067ebc627a22b12aac523a9606b92 (patch)
treec95a6202480cf2908f16a5e41069b1c3a27bdb24 /themes
parent9e9831fcf22cf77a797eb277f7155c442ff77f16 (diff)
downloadzsh-74a3db75e46067ebc627a22b12aac523a9606b92.tar.gz
zsh-74a3db75e46067ebc627a22b12aac523a9606b92.tar.bz2
zsh-74a3db75e46067ebc627a22b12aac523a9606b92.zip
perf(bureau): remove multiple grep calls in git status check
Diffstat (limited to 'themes')
-rw-r--r--themes/bureau.zsh-theme36
1 files changed, 19 insertions, 17 deletions
diff --git a/themes/bureau.zsh-theme b/themes/bureau.zsh-theme
index 3ca231f6f..a5a8a2b20 100644
--- a/themes/bureau.zsh-theme
+++ b/themes/bureau.zsh-theme
@@ -16,7 +16,7 @@ ZSH_THEME_GIT_PROMPT_STAGED="%{$fg_bold[green]%}●%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_UNSTAGED="%{$fg_bold[yellow]%}●%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$fg_bold[red]%}●%{$reset_color%}"
-bureau_git_branch () {
+bureau_git_info () {
local ref
ref=$(command git symbolic-ref HEAD 2> /dev/null) || \
ref=$(command git rev-parse --short HEAD 2> /dev/null) || return
@@ -30,16 +30,16 @@ bureau_git_status() {
# check status of files
local gitfiles="$(tail -n +2 <<< "$gitstatus")"
if [[ -n "$gitfiles" ]]; then
- if $(echo "$gitfiles" | command grep -q '^[AMRD]. '); then
+ if [[ "$gitfiles" =~ $'(^|\n)[AMRD]. ' ]]; then
result+="$ZSH_THEME_GIT_PROMPT_STAGED"
fi
- if $(echo "$gitfiles" | command grep -q '^.[MTD] '); then
+ if [[ "$gitfiles" =~ $'(^|\n).[MTD] ' ]]; then
result+="$ZSH_THEME_GIT_PROMPT_UNSTAGED"
fi
- if $(echo "$gitfiles" | command grep -q -E '^\?\? '); then
+ if [[ "$gitfiles" =~ $'(^|\n)\\?\\? ' ]]; then
result+="$ZSH_THEME_GIT_PROMPT_UNTRACKED"
fi
- if $(echo "$gitfiles" | command grep -q '^UU '); then
+ if [[ "$gitfiles" =~ $'(^|\n)UU ' ]]; then
result+="$ZSH_THEME_GIT_PROMPT_UNMERGED"
fi
else
@@ -48,17 +48,18 @@ bureau_git_status() {
# check status of local repository
local gitbranch="$(head -n 1 <<< "$gitstatus")"
- if $(echo "$gitbranch" | command grep -q '^## .*ahead'); then
+ if [[ "$gitbranch" =~ '^## .*ahead' ]]; then
result+="$ZSH_THEME_GIT_PROMPT_AHEAD"
fi
- if $(echo "$gitbranch" | command grep -q '^## .*behind'); then
+ if [[ "$gitbranch" =~ '^## .*behind' ]]; then
result+="$ZSH_THEME_GIT_PROMPT_BEHIND"
fi
- if $(echo "$gitbranch" | command grep -q '^## .*diverged'); then
+ if [[ "$gitbranch" =~ '^## .*diverged' ]]; then
result+="$ZSH_THEME_GIT_PROMPT_DIVERGED"
fi
- if $(command git rev-parse --verify refs/stash &> /dev/null); then
+ # check if there are stashed changes
+ if command git rev-parse --verify refs/stash &> /dev/null; then
result+="$ZSH_THEME_GIT_PROMPT_STASHED"
fi
@@ -66,21 +67,22 @@ bureau_git_status() {
}
bureau_git_prompt() {
- local gitbranch=$(bureau_git_branch)
- local gitstatus=$(bureau_git_status)
- local info
-
- if [[ -z "$gitbranch" ]]; then
+ # check git information
+ local gitinfo=$(bureau_git_info)
+ if [[ -z "$gitinfo" ]]; then
return
fi
- info="${gitbranch:gs/%/%%}"
+ # quote % in git information
+ local output="${gitinfo:gs/%/%%}"
+ # check git status
+ local gitstatus=$(bureau_git_status)
if [[ -n "$gitstatus" ]]; then
- info+=" $gitstatus"
+ output+=" $gitstatus"
fi
- echo "${ZSH_THEME_GIT_PROMPT_PREFIX}${info}${ZSH_THEME_GIT_PROMPT_SUFFIX}"
+ echo "${ZSH_THEME_GIT_PROMPT_PREFIX}${output}${ZSH_THEME_GIT_PROMPT_SUFFIX}"
}