]> git.rmz.io Git - dotfiles.git/commitdiff
zsh/prompt: tidy git_prompt, fix bolded worktree counts
authorSamir Benmendil <me@rmz.io>
Tue, 15 Mar 2022 13:33:38 +0000 (13:33 +0000)
committerSamir Benmendil <me@rmz.io>
Tue, 15 Mar 2022 13:33:38 +0000 (13:33 +0000)
In some occasions the worktree counters where bolded when they
shouldn't.

zsh/lib/prompt.zsh

index fa894be16eaf9dc3f86030567d4c5bb80f02a305..c249210bbaa542c470fd6042971d974a21ac81d0 100644 (file)
@@ -75,47 +75,45 @@ git_prompt_status() {
     fi
   done < <(${(z)status_cmd} 2> /dev/null)
 
-  local git_status=" %{$fg_bold[green]%}"
+  local git_status=" "
 
   # Format branch and commit
-  git_status+="$head%{$fg_no_bold[yellow]%}(${oid[1,8]})"
+  git_status+="%{$fg_bold[green]%}$head"
+  git_status+="%{$fg_no_bold[yellow]%}(${oid[1,8]})"
 
   # Format upstream
-  local upstream_str
-  [[ -z "$upstream" ]] && upstream_str+="%{$fg[blue]%} Ɇ"
-  (( ahead  > 0 )) && upstream_str+="%{$fg[blue]%} >$ahead"
-  (( behind > 0 )) && upstream_str+="%{$fg[blue]%} <$behind"
-  git_status+="$upstream_str"
+  git_status+="%{$fg[blue]%}"
+  [[ -z "$upstream" ]] && git_status+=" Ɇ"
+  (( ahead  > 0 ))     && git_status+=" >$ahead"
+  (( behind > 0 ))     && git_status+=" <$behind"
 
   # Format push
+  git_status+="%{$fg_bold[blue]%}"
   push_ab=( $(git rev-list --left-right --count @...@{push} 2>/dev/null) )
   if (( $? == 0 )); then
-    (( push_ab[1] > 0 )) && git_status+="%{$fg_bold[blue]%} ⮝$push_ab[1]"
-    (( push_ab[2] > 0 )) && git_status+="%{$fg_bold[blue]%} ⮟$push_ab[2]"
+    (( push_ab[1] > 0 )) && git_status+=" ⮝$push_ab[1]"
+    (( push_ab[2] > 0 )) && git_status+=" ⮟$push_ab[2]"
   fi
 
   # Format stashed
+  git_status+="%{$fg_bold[cyan]%}"
   stashed=$(git stash list | wc -l)
-  if (( stashed > 0 )) then
-    stashed_str+="%{$fg_bold[cyan]%} ⋎$stashed%{$reset_color%}"
-  fi
-  git_status+="$stashed_str"
+  (( stashed > 0 )) && git_status+=" ⋎$stashed"
 
   # Format index
-  local index_str
-  (( updated > 0 )) && index_str+="%{$fg[green]%} *$updated"
-  (( added   > 0 )) && index_str+="%{$fg[green]%} +$added"
-  (( deleted > 0 )) && index_str+="%{$fg[green]%} -$deleted"
-  (( renamed > 0 )) && index_str+="%{$fg[green]%} ≈$renamed"
-  git_status+="$index_str"
+  git_status+="%{$fg_no_bold[green]%}"
+  (( updated > 0 )) && git_status+=" *$updated"
+  (( added   > 0 )) && git_status+=" +$added"
+  (( deleted > 0 )) && git_status+=" -$deleted"
+  (( renamed > 0 )) && git_status+=" ≈$renamed"
 
   # Format working tree
-  local wt_str
-  (( modified   > 0 )) && wt_str+="%{$fg[red]%} *$modified"
-  (( deleted_wt > 0 )) && wt_str+="%{$fg[red]%} -$deleted_wt"
-  (( untracked  > 0 )) && wt_str+="%{$fg[red]%} +$untracked"
-  (( unmerged   > 0 )) && wt_str+="%{$fg[magenta]%} ♒$unmerged"
-  git_status+="$wt_str"
+  git_status+="%{$fg_no_bold[red]%}"
+  (( modified   > 0 )) && git_status+=" *$modified"
+  (( deleted_wt > 0 )) && git_status+=" -$deleted_wt"
+  (( untracked  > 0 )) && git_status+=" +$untracked"
+  git_status+="%{$fg_no_bold[magenta]%}"
+  (( unmerged   > 0 )) && git_status+=" ♒$unmerged"
 
   git_status+="%{$reset_color%}"