fix(bureau): fix status variable name causing error (#10561)

Also cleaned up the code a bit

Fixes #10561
This commit is contained in:
Marc Cornellà 2022-01-03 17:05:48 +01:00
parent d87ab251c7
commit 8e973d42bd
No known key found for this signature in database
GPG key ID: 0314585E776A9C1B

View file

@ -24,59 +24,58 @@ bureau_git_branch () {
} }
bureau_git_status() { bureau_git_status() {
local _STATUS _INDEX local result gitstatus
# check status of files # check status of files
_INDEX=$(command git status --porcelain 2> /dev/null) gitstatus=$(command git status --porcelain -b 2> /dev/null)
if [[ -n "$_INDEX" ]]; then if [[ -n "$gitstatus" ]]; then
if $(echo "$_INDEX" | command grep -q '^[AMRD]. '); then if $(echo "$gitstatus" | command grep -q '^[AMRD]. '); then
_STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_STAGED" result+="$ZSH_THEME_GIT_PROMPT_STAGED"
fi fi
if $(echo "$_INDEX" | command grep -q '^.[MTD] '); then if $(echo "$gitstatus" | command grep -q '^.[MTD] '); then
_STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_UNSTAGED" result+="$ZSH_THEME_GIT_PROMPT_UNSTAGED"
fi fi
if $(echo "$_INDEX" | command grep -q -E '^\?\? '); then if $(echo "$gitstatus" | command grep -q -E '^\?\? '); then
_STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_UNTRACKED" result+="$ZSH_THEME_GIT_PROMPT_UNTRACKED"
fi fi
if $(echo "$_INDEX" | command grep -q '^UU '); then if $(echo "$gitstatus" | command grep -q '^UU '); then
_STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_UNMERGED" result+="$ZSH_THEME_GIT_PROMPT_UNMERGED"
fi fi
else else
_STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_CLEAN" result+="$ZSH_THEME_GIT_PROMPT_CLEAN"
fi fi
# check status of local repository # check status of local repository
_INDEX=$(command git status --porcelain -b 2> /dev/null) if $(echo "$gitstatus" | command grep -q '^## .*ahead'); then
if $(echo "$_INDEX" | command grep -q '^## .*ahead'); then result+="$ZSH_THEME_GIT_PROMPT_AHEAD"
_STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_AHEAD"
fi fi
if $(echo "$_INDEX" | command grep -q '^## .*behind'); then if $(echo "$gitstatus" | command grep -q '^## .*behind'); then
_STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_BEHIND" result+="$ZSH_THEME_GIT_PROMPT_BEHIND"
fi fi
if $(echo "$_INDEX" | command grep -q '^## .*diverged'); then if $(echo "$gitstatus" | command grep -q '^## .*diverged'); then
_STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_DIVERGED" result+="$ZSH_THEME_GIT_PROMPT_DIVERGED"
fi fi
if $(command git rev-parse --verify refs/stash &> /dev/null); then if $(command git rev-parse --verify refs/stash &> /dev/null); then
_STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_STASHED" result+="$ZSH_THEME_GIT_PROMPT_STASHED"
fi fi
echo $_STATUS echo $result
} }
bureau_git_prompt() { bureau_git_prompt() {
local branch=$(bureau_git_branch) local gitbranch=$(bureau_git_branch)
local status=$(bureau_git_status) local gitstatus=$(bureau_git_status)
local info local info
if [[ -z "${branch}" ]]; then if [[ -z "$gitbranch" ]]; then
return return
fi fi
info="${branch:gs/%/%%}" info="${gitbranch:gs/%/%%}"
if [[ -n "${status}" ]]; then if [[ -n "$gitstatus" ]]; then
info+=" $status" info+=" $gitstatus"
fi fi
echo "${ZSH_THEME_GIT_PROMPT_PREFIX}${info}${ZSH_THEME_GIT_PROMPT_SUFFIX}" echo "${ZSH_THEME_GIT_PROMPT_PREFIX}${info}${ZSH_THEME_GIT_PROMPT_SUFFIX}"