zsh: use array for colors in git prompt
This commit is contained in:
parent
4b779b8336
commit
39ead8b9ee
1 changed files with 18 additions and 16 deletions
|
@ -84,14 +84,16 @@ fs_prompt_pwd() {
|
|||
|
||||
fs_prompt_git() {
|
||||
typeset -A icons=([branch]="$1" [tag]="$2" [detached]="$3")
|
||||
local branch_color="$4"
|
||||
local ahead_color="$5"
|
||||
local behind_color="$6"
|
||||
local untracked_color="$7"
|
||||
local staged_color="$8"
|
||||
local dirty_color="$9"
|
||||
local conflict_color="$10"
|
||||
local sep_color="$11"
|
||||
typeset -A fg=(
|
||||
[branch]="$4"
|
||||
[ahead]="$5"
|
||||
[behind]="$6"
|
||||
[untracked]="$7"
|
||||
[staged]="$8"
|
||||
[dirty]="$9"
|
||||
[conflict]="$10"
|
||||
[sep]="$11"
|
||||
)
|
||||
|
||||
local gitstatus # local swallows git's exit code if not on its own line
|
||||
gitstatus=$(command git status --porcelain -b 2>/dev/null) || return
|
||||
|
@ -156,22 +158,22 @@ fs_prompt_git() {
|
|||
|
||||
local result=()
|
||||
{
|
||||
local sep="${sep_color}"
|
||||
local sep="${fg[sep]}"
|
||||
local tracking=()
|
||||
(($ahead)) && tracking+="${ahead_color}${ahead}" # ↑
|
||||
(($behind)) && tracking+="${behind_color}${behind}" # ↓
|
||||
(($ahead)) && tracking+="${fg[ahead]}${ahead}" # ↑
|
||||
(($behind)) && tracking+="${fg[behind]}${behind}" # ↓
|
||||
(($#tracking)) && result+="${(pj:$sep:)tracking}"
|
||||
|
||||
(($conflicts)) && result+="${conflict_color} %{%B%}${conflicts}%{%b%}"
|
||||
(($conflicts)) && result+="${fg[conflict]} %{%B%}${conflicts}%{%b%}"
|
||||
|
||||
local state=()
|
||||
(($staged)) && state+="${staged_color}+${staged}"
|
||||
(($dirty)) && state+="${dirty_color}${dirty}✶"
|
||||
(($staged)) && state+="${fg[staged]}+${staged}"
|
||||
(($dirty)) && state+="${fg[dirty]}${dirty}✶"
|
||||
(($#state)) && result+="${(pj:$sep:)state}"
|
||||
|
||||
(($untracked)) && result+="${untracked_color}${untracked}?"
|
||||
(($untracked)) && result+="${fg[untracked]}${untracked}?"
|
||||
}
|
||||
print "${branch_color}${branch} ${(j: :)result}"
|
||||
print "${fg[branch]}${branch} ${(j: :)result}"
|
||||
}
|
||||
|
||||
fs_prompt_virtualenv() {
|
||||
|
|
Loading…
Add table
Reference in a new issue