From 43be5ea32150912ae2e85e2cc278c092022ea53f Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Mon, 27 Dec 2021 00:38:58 +0100 Subject: fix(bureau): quote % in git prompt function and remove global variables --- themes/bureau.zsh-theme | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) (limited to 'themes/bureau.zsh-theme') diff --git a/themes/bureau.zsh-theme b/themes/bureau.zsh-theme index 3b3bdc80f..7a253a688 100644 --- a/themes/bureau.zsh-theme +++ b/themes/bureau.zsh-theme @@ -17,13 +17,14 @@ ZSH_THEME_GIT_PROMPT_UNSTAGED="%{$fg_bold[yellow]%}●%{$reset_color%}" ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$fg_bold[red]%}●%{$reset_color%}" bureau_git_branch () { + local ref ref=$(command git symbolic-ref HEAD 2> /dev/null) || \ ref=$(command git rev-parse --short HEAD 2> /dev/null) || return echo "${ref#refs/heads/}" } bureau_git_status() { - _STATUS="" + local _STATUS _INDEX # check status of files _INDEX=$(command git status --porcelain 2> /dev/null) @@ -63,18 +64,22 @@ bureau_git_status() { echo $_STATUS } -bureau_git_prompt () { - local _branch=$(bureau_git_branch) - local _status=$(bureau_git_status) - local _result="" - if [[ "${_branch}x" != "x" ]]; then - _result="$ZSH_THEME_GIT_PROMPT_PREFIX$_branch" - if [[ "${_status}x" != "x" ]]; then - _result="$_result $_status" - fi - _result="$_result$ZSH_THEME_GIT_PROMPT_SUFFIX" +bureau_git_prompt() { + local branch=$(bureau_git_branch) + local status=$(bureau_git_status) + local info + + if [[ -z "${branch}" ]]; then + return + fi + + info="${branch:gs/%/%%}" + + if [[ -n "${status}" ]]; then + info+=" $status" fi - echo $_result + + echo "${ZSH_THEME_GIT_PROMPT_PREFIX}${info}${ZSH_THEME_GIT_PROMPT_SUFFIX}" } -- cgit v1.2.3-70-g09d2 From 8e973d42bd3bc5028d88ce731113b03ac8a5590c Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Mon, 3 Jan 2022 17:05:48 +0100 Subject: fix(bureau): fix `status` variable name causing error (#10561) Also cleaned up the code a bit Fixes #10561 --- themes/bureau.zsh-theme | 53 ++++++++++++++++++++++++------------------------- 1 file changed, 26 insertions(+), 27 deletions(-) (limited to 'themes/bureau.zsh-theme') diff --git a/themes/bureau.zsh-theme b/themes/bureau.zsh-theme index 7a253a688..50058e213 100644 --- a/themes/bureau.zsh-theme +++ b/themes/bureau.zsh-theme @@ -24,59 +24,58 @@ bureau_git_branch () { } bureau_git_status() { - local _STATUS _INDEX + local result gitstatus # check status of files - _INDEX=$(command git status --porcelain 2> /dev/null) - if [[ -n "$_INDEX" ]]; then - if $(echo "$_INDEX" | command grep -q '^[AMRD]. '); then - _STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_STAGED" + gitstatus=$(command git status --porcelain -b 2> /dev/null) + if [[ -n "$gitstatus" ]]; then + if $(echo "$gitstatus" | command grep -q '^[AMRD]. '); then + result+="$ZSH_THEME_GIT_PROMPT_STAGED" fi - if $(echo "$_INDEX" | command grep -q '^.[MTD] '); then - _STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_UNSTAGED" + if $(echo "$gitstatus" | command grep -q '^.[MTD] '); then + result+="$ZSH_THEME_GIT_PROMPT_UNSTAGED" fi - if $(echo "$_INDEX" | command grep -q -E '^\?\? '); then - _STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_UNTRACKED" + if $(echo "$gitstatus" | command grep -q -E '^\?\? '); then + result+="$ZSH_THEME_GIT_PROMPT_UNTRACKED" fi - if $(echo "$_INDEX" | command grep -q '^UU '); then - _STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_UNMERGED" + if $(echo "$gitstatus" | command grep -q '^UU '); then + result+="$ZSH_THEME_GIT_PROMPT_UNMERGED" fi else - _STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_CLEAN" + result+="$ZSH_THEME_GIT_PROMPT_CLEAN" fi # check status of local repository - _INDEX=$(command git status --porcelain -b 2> /dev/null) - if $(echo "$_INDEX" | command grep -q '^## .*ahead'); then - _STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_AHEAD" + if $(echo "$gitstatus" | command grep -q '^## .*ahead'); then + result+="$ZSH_THEME_GIT_PROMPT_AHEAD" fi - if $(echo "$_INDEX" | command grep -q '^## .*behind'); then - _STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_BEHIND" + if $(echo "$gitstatus" | command grep -q '^## .*behind'); then + result+="$ZSH_THEME_GIT_PROMPT_BEHIND" fi - if $(echo "$_INDEX" | command grep -q '^## .*diverged'); then - _STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_DIVERGED" + if $(echo "$gitstatus" | command grep -q '^## .*diverged'); then + result+="$ZSH_THEME_GIT_PROMPT_DIVERGED" fi 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 - echo $_STATUS + echo $result } bureau_git_prompt() { - local branch=$(bureau_git_branch) - local status=$(bureau_git_status) + local gitbranch=$(bureau_git_branch) + local gitstatus=$(bureau_git_status) local info - if [[ -z "${branch}" ]]; then + if [[ -z "$gitbranch" ]]; then return fi - info="${branch:gs/%/%%}" + info="${gitbranch:gs/%/%%}" - if [[ -n "${status}" ]]; then - info+=" $status" + if [[ -n "$gitstatus" ]]; then + info+=" $gitstatus" fi echo "${ZSH_THEME_GIT_PROMPT_PREFIX}${info}${ZSH_THEME_GIT_PROMPT_SUFFIX}" -- cgit v1.2.3-70-g09d2 From 9e9831fcf22cf77a797eb277f7155c442ff77f16 Mon Sep 17 00:00:00 2001 From: Harris Miller Date: Fri, 4 Feb 2022 13:08:03 -0700 Subject: fix(bureau): fix never `CLEAN` git status (#10656) Closes #10656 --- themes/bureau.zsh-theme | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'themes/bureau.zsh-theme') diff --git a/themes/bureau.zsh-theme b/themes/bureau.zsh-theme index 50058e213..3ca231f6f 100644 --- a/themes/bureau.zsh-theme +++ b/themes/bureau.zsh-theme @@ -25,20 +25,21 @@ bureau_git_branch () { bureau_git_status() { local result gitstatus + gitstatus="$(command git status --porcelain -b 2>/dev/null)" # check status of files - gitstatus=$(command git status --porcelain -b 2> /dev/null) - if [[ -n "$gitstatus" ]]; then - if $(echo "$gitstatus" | command grep -q '^[AMRD]. '); then + local gitfiles="$(tail -n +2 <<< "$gitstatus")" + if [[ -n "$gitfiles" ]]; then + if $(echo "$gitfiles" | command grep -q '^[AMRD]. '); then result+="$ZSH_THEME_GIT_PROMPT_STAGED" fi - if $(echo "$gitstatus" | command grep -q '^.[MTD] '); then + if $(echo "$gitfiles" | command grep -q '^.[MTD] '); then result+="$ZSH_THEME_GIT_PROMPT_UNSTAGED" fi - if $(echo "$gitstatus" | command grep -q -E '^\?\? '); then + if $(echo "$gitfiles" | command grep -q -E '^\?\? '); then result+="$ZSH_THEME_GIT_PROMPT_UNTRACKED" fi - if $(echo "$gitstatus" | command grep -q '^UU '); then + if $(echo "$gitfiles" | command grep -q '^UU '); then result+="$ZSH_THEME_GIT_PROMPT_UNMERGED" fi else @@ -46,13 +47,14 @@ bureau_git_status() { fi # check status of local repository - if $(echo "$gitstatus" | command grep -q '^## .*ahead'); then + local gitbranch="$(head -n 1 <<< "$gitstatus")" + if $(echo "$gitbranch" | command grep -q '^## .*ahead'); then result+="$ZSH_THEME_GIT_PROMPT_AHEAD" fi - if $(echo "$gitstatus" | command grep -q '^## .*behind'); then + if $(echo "$gitbranch" | command grep -q '^## .*behind'); then result+="$ZSH_THEME_GIT_PROMPT_BEHIND" fi - if $(echo "$gitstatus" | command grep -q '^## .*diverged'); then + if $(echo "$gitbranch" | command grep -q '^## .*diverged'); then result+="$ZSH_THEME_GIT_PROMPT_DIVERGED" fi -- cgit v1.2.3-70-g09d2 From 74a3db75e46067ebc627a22b12aac523a9606b92 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Mon, 7 Feb 2022 17:44:05 +0100 Subject: perf(bureau): remove multiple grep calls in git status check --- themes/bureau.zsh-theme | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) (limited to 'themes/bureau.zsh-theme') 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}" } -- cgit v1.2.3-70-g09d2 From 1e26ad1187cdee286d0332dbdffb6828a71140c2 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Mon, 7 Feb 2022 17:52:57 +0100 Subject: fix(bureau): fix top line space computation Takes into account $ZLE_RPROMPT_INDENT and doesn't add the extra space at the end so it doesn't bleed into the next line. --- themes/bureau.zsh-theme | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'themes/bureau.zsh-theme') diff --git a/themes/bureau.zsh-theme b/themes/bureau.zsh-theme index a5a8a2b20..698aa2ff8 100644 --- a/themes/bureau.zsh-theme +++ b/themes/bureau.zsh-theme @@ -103,19 +103,14 @@ get_space () { local STR=$1$2 local zero='%([BSUbfksu]|([FB]|){*})' local LENGTH=${#${(S%%)STR//$~zero/}} - local SPACES="" - (( LENGTH = ${COLUMNS} - $LENGTH - 1)) + local SPACES=$(( COLUMNS - LENGTH - ${ZLE_RPROMPT_INDENT:-1} )) - for i in {0..$LENGTH} - do - SPACES="$SPACES " - done - - echo $SPACES + (( SPACES > 0 )) || return + printf ' %.0s' {1..$SPACES} } _1LEFT="$_USERNAME $_PATH" -_1RIGHT="[%*] " +_1RIGHT="[%*]" bureau_precmd () { _1SPACES=`get_space $_1LEFT $_1RIGHT` -- cgit v1.2.3-70-g09d2