From d942a47ef562d848d21c5b672d36b0e082e3cfea Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Tue, 21 Jan 2020 13:12:05 +0000 Subject: [PATCH] Display whether the repo is dirty in the prompt --- tag-zsh/zsh/configs/prompt.zsh | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/tag-zsh/zsh/configs/prompt.zsh b/tag-zsh/zsh/configs/prompt.zsh index 7c76bad..4afe7a4 100644 --- a/tag-zsh/zsh/configs/prompt.zsh +++ b/tag-zsh/zsh/configs/prompt.zsh @@ -1,7 +1,25 @@ +git_current_branch() { + echo $(git rev-parse --abbrev-ref HEAD) +} + +git_repo_is_dirty() { + if [[ -z $(git status --short) ]]; then + return 1; + fi + + return 0; +} + git_prompt_info() { - current_branch=$(git current-branch 2> /dev/null) - if [[ -n $current_branch ]]; then - echo " %{$fg_bold[green]%}$current_branch%{$reset_color%}" + current_branch=$(git_current_branch 2> /dev/null) + suffix='' + + if git_repo_is_dirty; then + suffix=" %{$fg_bold[red]%}*%{$reset_color%}" + fi + + if [[ -n git_current_branch ]]; then + echo " %{$fg_bold[green]%}${current_branch}${suffix}%{$reset_color%}" fi }