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() {
|
fs_prompt_git() {
|
||||||
typeset -A icons=([branch]="$1" [tag]="$2" [detached]="$3")
|
typeset -A icons=([branch]="$1" [tag]="$2" [detached]="$3")
|
||||||
local branch_color="$4"
|
typeset -A fg=(
|
||||||
local ahead_color="$5"
|
[branch]="$4"
|
||||||
local behind_color="$6"
|
[ahead]="$5"
|
||||||
local untracked_color="$7"
|
[behind]="$6"
|
||||||
local staged_color="$8"
|
[untracked]="$7"
|
||||||
local dirty_color="$9"
|
[staged]="$8"
|
||||||
local conflict_color="$10"
|
[dirty]="$9"
|
||||||
local sep_color="$11"
|
[conflict]="$10"
|
||||||
|
[sep]="$11"
|
||||||
|
)
|
||||||
|
|
||||||
local gitstatus # local swallows git's exit code if not on its own line
|
local gitstatus # local swallows git's exit code if not on its own line
|
||||||
gitstatus=$(command git status --porcelain -b 2>/dev/null) || return
|
gitstatus=$(command git status --porcelain -b 2>/dev/null) || return
|
||||||
|
@ -156,22 +158,22 @@ fs_prompt_git() {
|
||||||
|
|
||||||
local result=()
|
local result=()
|
||||||
{
|
{
|
||||||
local sep="${sep_color}"
|
local sep="${fg[sep]}"
|
||||||
local tracking=()
|
local tracking=()
|
||||||
(($ahead)) && tracking+="${ahead_color}${ahead}" # ↑
|
(($ahead)) && tracking+="${fg[ahead]}${ahead}" # ↑
|
||||||
(($behind)) && tracking+="${behind_color}${behind}" # ↓
|
(($behind)) && tracking+="${fg[behind]}${behind}" # ↓
|
||||||
(($#tracking)) && result+="${(pj:$sep:)tracking}"
|
(($#tracking)) && result+="${(pj:$sep:)tracking}"
|
||||||
|
|
||||||
(($conflicts)) && result+="${conflict_color} %{%B%}${conflicts}%{%b%}"
|
(($conflicts)) && result+="${fg[conflict]} %{%B%}${conflicts}%{%b%}"
|
||||||
|
|
||||||
local state=()
|
local state=()
|
||||||
(($staged)) && state+="${staged_color}+${staged}"
|
(($staged)) && state+="${fg[staged]}+${staged}"
|
||||||
(($dirty)) && state+="${dirty_color}${dirty}✶"
|
(($dirty)) && state+="${fg[dirty]}${dirty}✶"
|
||||||
(($#state)) && result+="${(pj:$sep:)state}"
|
(($#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() {
|
fs_prompt_virtualenv() {
|
||||||
|
|
Loading…
Add table
Reference in a new issue