diff options
author | Tuowen Zhao <ztuowen@gmail.com> | 2022-02-19 17:12:23 -0600 |
---|---|---|
committer | Tuowen Zhao <ztuowen@gmail.com> | 2022-02-19 17:12:23 -0600 |
commit | cae9a2b797649379e865e6bd73bc67e294e4ac77 (patch) | |
tree | 481419eff4bc761c3ca516704427394193473419 /themes/bureau.zsh-theme | |
parent | 49edbf438ed690c76e6b2af80368c59404cf0167 (diff) | |
parent | 3427da4057dbe302933a7b5b19b4e23bfb9d0969 (diff) | |
download | zsh-cae9a2b797649379e865e6bd73bc67e294e4ac77.tar.gz zsh-cae9a2b797649379e865e6bd73bc67e294e4ac77.tar.bz2 zsh-cae9a2b797649379e865e6bd73bc67e294e4ac77.zip |
Merge remote-tracking branch 'origin/master'
Diffstat (limited to 'themes/bureau.zsh-theme')
-rw-r--r-- | themes/bureau.zsh-theme | 89 |
1 files changed, 46 insertions, 43 deletions
diff --git a/themes/bureau.zsh-theme b/themes/bureau.zsh-theme index 3b3bdc80f..698aa2ff8 100644 --- a/themes/bureau.zsh-theme +++ b/themes/bureau.zsh-theme @@ -16,65 +16,73 @@ 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 echo "${ref#refs/heads/}" } bureau_git_status() { - _STATUS="" + local result gitstatus + gitstatus="$(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 -q '^[AMRD]. '); then - _STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_STAGED" + local gitfiles="$(tail -n +2 <<< "$gitstatus")" + if [[ -n "$gitfiles" ]]; then + if [[ "$gitfiles" =~ $'(^|\n)[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 [[ "$gitfiles" =~ $'(^|\n).[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 [[ "$gitfiles" =~ $'(^|\n)\\?\\? ' ]]; then + result+="$ZSH_THEME_GIT_PROMPT_UNTRACKED" fi - if $(echo "$_INDEX" | command grep -q '^UU '); then - _STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_UNMERGED" + if [[ "$gitfiles" =~ $'(^|\n)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" + local gitbranch="$(head -n 1 <<< "$gitstatus")" + if [[ "$gitbranch" =~ '^## .*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 [[ "$gitbranch" =~ '^## .*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 [[ "$gitbranch" =~ '^## .*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" + # check if there are stashed changes + if command git rev-parse --verify refs/stash &> /dev/null; then + 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 _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() { + # check git information + local gitinfo=$(bureau_git_info) + if [[ -z "$gitinfo" ]]; then + return + fi + + # quote % in git information + local output="${gitinfo:gs/%/%%}" + + # check git status + local gitstatus=$(bureau_git_status) + if [[ -n "$gitstatus" ]]; then + output+=" $gitstatus" fi - echo $_result + + echo "${ZSH_THEME_GIT_PROMPT_PREFIX}${output}${ZSH_THEME_GIT_PROMPT_SUFFIX}" } @@ -95,19 +103,14 @@ get_space () { local STR=$1$2 local zero='%([BSUbfksu]|([FB]|){*})' local LENGTH=${#${(S%%)STR//$~zero/}} - local SPACES="" - (( LENGTH = ${COLUMNS} - $LENGTH - 1)) - - for i in {0..$LENGTH} - do - SPACES="$SPACES " - done + local SPACES=$(( COLUMNS - LENGTH - ${ZLE_RPROMPT_INDENT:-1} )) - echo $SPACES + (( SPACES > 0 )) || return + printf ' %.0s' {1..$SPACES} } _1LEFT="$_USERNAME $_PATH" -_1RIGHT="[%*] " +_1RIGHT="[%*]" bureau_precmd () { _1SPACES=`get_space $_1LEFT $_1RIGHT` |