I am trying to customize the Bira zsh-theme so that a clean branch is green and a dirty branch is red and has an asterisk at the end like so...
I have gotten it so that the color changes based on the branch's state, but cannot figure out how to get the asterisk to show up at the end. Below is what I have so far. I'm very new to customizing zsh-theme files, so any help would be much appreciated!
# ZSH Theme - Modified from bira.zsh-theme
local return_code="%(?..%{$fg[red]%}%? ↵%{$reset_color%})"
if [[ $UID -eq 0 ]]; then
local user_host='%{$terminfo[bold]$fg[red]%}%n@%m%{$reset_color%}'
local user_symbol='#'
else
local user_host='%{$terminfo[bold]$fg[cyan]%}%n@%m%{$reset_color%}'
local user_symbol='$'
fi
local current_dir='%{$terminfo[bold]$fg[yellow]%}%~%{$reset_color%}'
local git_branch='$(git_prompt_info)%{$reset_color%}'
function git_prompt_info() {
ref=$(git symbolic-ref HEAD 2> /dev/null) || return
echo "$(parse_git_dirty)$ZSH_THEME_GIT_PROMPT_PREFIX$(current_branch)$ZSH_THEME_GIT_PROMPT_SUFFIX"
}
PROMPT="
╭─${user_host} ${current_dir} ${git_branch}
╰─%B${user_symbol}%b "
RPS1="%B${return_code}%b"
ZSH_THEME_GIT_PROMPT_PREFIX="‹"
ZSH_THEME_GIT_PROMPT_SUFFIX="›$reset_color"
ZSH_THEME_GIT_PROMPT_DIRTY="$fg[red]"
ZSH_THEME_GIT_PROMPT_CLEAN="$fg[green]"
The
parse_git_dirty
function is defined inlib/git.zsh
By copying that function into your file and modifying it slightly, we can achieve what you want:
The only difference from the library function is assigning
GIT_PROMPT_COLOR
andGIT_DIRTY_STAR
instead of echoing, and then using these in the final echo.