show staged, behind; multi-coloured git status

Signed-off-by: fbt <fbt@fleshless.org>
This commit is contained in:
Jack L. Frost 2017-11-09 18:01:24 +03:00
parent 631986f76a
commit 3545721a7c
1 changed files with 9 additions and 16 deletions

View File

@ -69,27 +69,21 @@ precmd.git() {
[[ $line[1,2] == '##' ]] && git_branch_info=$line[4,-1] [[ $line[1,2] == '##' ]] && git_branch_info=$line[4,-1]
[[ $line[1,2] == '??' ]] && (( git_untracked++ )) [[ $line[1,2] == '??' ]] && (( git_untracked++ ))
[[ $line[1,2] =~ .[MD] ]] && (( git_unstaged++ )) [[ $line[1,2] =~ .[MD] ]] && (( git_unstaged++ ))
[[ $line[1,2] =~ [MDARC]. ]] && (( git_staged++ ))
done < <(git status --porcelain -bu 2>/dev/null) done < <(git status --porcelain -bu 2>/dev/null)
git_branch_name=${git_branch_info%%...*} git_branch_name=${git_branch_info%%...*}
[[ $git_branch_info =~ ahead\ ([0-9]+) ]] && git_ahead=$match[1] [[ $git_branch_info =~ ahead\ ([0-9]+) ]] && git_ahead=$match[1]
[[ $git_branch_info =~ behind\ ([0-9]+) ]] && git_behind=$match[1]
git_status_colour='green' git_status_colour='green'
(( git_ahead )) && { _c() { printf '%%F{%s}%s%%f' "$@" }
git_status_short+='a' (( git_ahead )) && git_status_short+=$(_c yellow a)
git_status_colour='yellow' (( git_behind )) && git_status_short+=$(_c yellow b)
} (( git_staged )) && git_status_short+=$(_c red s)
(( git_unstaged )) && git_status_short+=$(_c red c)
(( git_unstaged )) && { (( git_untracked )) && git_status_short+=$(_c red f)
git_status_short+='c'
git_status_colour='red'
}
(( git_untracked )) && {
git_status_short+='f'
git_status_colour='red'
}
git_status_short=${git_status_short:-"ok"} git_status_short=${git_status_short:-"ok"}
git_prompt_msg="(%F{cyan}$git_branch_name%f[%F{$git_status_colour}${git_status_short}%f]) " git_prompt_msg="(%F{cyan}$git_branch_name%f[%F{$git_status_colour}${git_status_short}%f]) "
@ -111,8 +105,7 @@ TRAPUSR1() {
draw_prompt() { draw_prompt() {
prompt_custom=( prompt_custom=(
"%F{$cmd_colour}$cmd_msg%f" "%F{$cmd_colour}$cmd_msg%f"
"%F{$user_colour}$USER%f@$HOST" "%F{$user_colour}$USER%f $HOST:${PWD//$HOME/~}"
"${PWD//$HOME/~}"
"$prompt_async_data%F{$user_colour}>%f" "$prompt_async_data%F{$user_colour}>%f"
) )