From e1b04cfecd87d1e39656be07df8f73a4ea113b8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Mon, 4 Apr 2016 20:39:10 +0200 Subject: [PATCH 1/2] Fix logic of bureau_git_status function This separates the gathering of file status, repository status and stash. --- themes/bureau.zsh-theme | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/themes/bureau.zsh-theme b/themes/bureau.zsh-theme index c6296500d..9b1759c1b 100644 --- a/themes/bureau.zsh-theme +++ b/themes/bureau.zsh-theme @@ -22,10 +22,12 @@ bureau_git_branch () { echo "${ref#refs/heads/}" } -bureau_git_status () { +bureau_git_status() { _STATUS="" - if [[ $(command git status --short 2> /dev/null) != "" ]]; then - _INDEX=$(command git status --porcelain -b 2> /dev/null) + + # check status of files + _INDEX=$(command git status --porcelain 2> /dev/null) + if [[ -n "$_INDEX" ]]; then if $(echo "$_INDEX" | command grep '^[AMRD]. ' &> /dev/null); then _STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_STAGED" fi @@ -38,22 +40,26 @@ bureau_git_status () { if $(echo "$_INDEX" | command grep '^UU ' &> /dev/null); then _STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_UNMERGED" fi - if $(command git rev-parse --verify refs/stash >/dev/null 2>&1); then - _STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_STASHED" - fi - if $(echo "$_INDEX" | command grep '^## .*ahead' &> /dev/null); then - _STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_AHEAD" - fi - if $(echo "$_INDEX" | command grep '^## .*behind' &> /dev/null); then - _STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_BEHIND" - fi - if $(echo "$_INDEX" | command grep '^## .*diverged' &> /dev/null); then - _STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_DIVERGED" - fi else _STATUS="$_STATUS$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 '^## .*ahead' &> /dev/null); then + _STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_AHEAD" + fi + if $(echo "$_INDEX" | command grep '^## .*behind' &> /dev/null); then + _STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_BEHIND" + fi + if $(echo "$_INDEX" | command grep '^## .*diverged' &> /dev/null); then + _STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_DIVERGED" + fi + + if $(command git rev-parse --verify refs/stash &> /dev/null); then + _STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_STASHED" + fi + echo $_STATUS } From 82a4587427ea8246bf74858ace489c81690c3c28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Mon, 4 Apr 2016 23:06:08 +0200 Subject: [PATCH 2/2] Use `grep -q` for silent behavior --- themes/bureau.zsh-theme | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/themes/bureau.zsh-theme b/themes/bureau.zsh-theme index 9b1759c1b..3b3bdc80f 100644 --- a/themes/bureau.zsh-theme +++ b/themes/bureau.zsh-theme @@ -28,16 +28,16 @@ bureau_git_status() { # check status of files _INDEX=$(command git status --porcelain 2> /dev/null) if [[ -n "$_INDEX" ]]; then - if $(echo "$_INDEX" | command grep '^[AMRD]. ' &> /dev/null); then + if $(echo "$_INDEX" | command grep -q '^[AMRD]. '); then _STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_STAGED" fi - if $(echo "$_INDEX" | command grep '^.[MTD] ' &> /dev/null); then + if $(echo "$_INDEX" | command grep -q '^.[MTD] '); then _STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_UNSTAGED" fi - if $(echo "$_INDEX" | command grep -E '^\?\? ' &> /dev/null); then + if $(echo "$_INDEX" | command grep -q -E '^\?\? '); then _STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_UNTRACKED" fi - if $(echo "$_INDEX" | command grep '^UU ' &> /dev/null); then + if $(echo "$_INDEX" | command grep -q '^UU '); then _STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_UNMERGED" fi else @@ -46,13 +46,13 @@ bureau_git_status() { # check status of local repository _INDEX=$(command git status --porcelain -b 2> /dev/null) - if $(echo "$_INDEX" | command grep '^## .*ahead' &> /dev/null); then + if $(echo "$_INDEX" | command grep -q '^## .*ahead'); then _STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_AHEAD" fi - if $(echo "$_INDEX" | command grep '^## .*behind' &> /dev/null); then + if $(echo "$_INDEX" | command grep -q '^## .*behind'); then _STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_BEHIND" fi - if $(echo "$_INDEX" | command grep '^## .*diverged' &> /dev/null); then + if $(echo "$_INDEX" | command grep -q '^## .*diverged'); then _STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_DIVERGED" fi