show staged, behind; multi-coloured git status
Signed-off-by: fbt <fbt@fleshless.org>
This commit is contained in:
parent
631986f76a
commit
3545721a7c
|
@ -69,27 +69,21 @@ precmd.git() {
|
|||
[[ $line[1,2] == '##' ]] && git_branch_info=$line[4,-1]
|
||||
[[ $line[1,2] == '??' ]] && (( git_untracked++ ))
|
||||
[[ $line[1,2] =~ .[MD] ]] && (( git_unstaged++ ))
|
||||
[[ $line[1,2] =~ [MDARC]. ]] && (( git_staged++ ))
|
||||
done < <(git status --porcelain -bu 2>/dev/null)
|
||||
|
||||
git_branch_name=${git_branch_info%%...*}
|
||||
[[ $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_ahead )) && {
|
||||
git_status_short+='a'
|
||||
git_status_colour='yellow'
|
||||
}
|
||||
|
||||
(( git_unstaged )) && {
|
||||
git_status_short+='c'
|
||||
git_status_colour='red'
|
||||
}
|
||||
|
||||
(( git_untracked )) && {
|
||||
git_status_short+='f'
|
||||
git_status_colour='red'
|
||||
}
|
||||
_c() { printf '%%F{%s}%s%%f' "$@" }
|
||||
(( git_ahead )) && git_status_short+=$(_c yellow a)
|
||||
(( 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_untracked )) && git_status_short+=$(_c red f)
|
||||
|
||||
git_status_short=${git_status_short:-"ok"}
|
||||
git_prompt_msg="(%F{cyan}$git_branch_name%f[%F{$git_status_colour}${git_status_short}%f]) "
|
||||
|
@ -111,8 +105,7 @@ TRAPUSR1() {
|
|||
draw_prompt() {
|
||||
prompt_custom=(
|
||||
"%F{$cmd_colour}$cmd_msg%f"
|
||||
"%F{$user_colour}$USER%f@$HOST"
|
||||
"${PWD//$HOME/~}"
|
||||
"%F{$user_colour}$USER%f $HOST:${PWD//$HOME/~}"
|
||||
"$prompt_async_data%F{$user_colour}>%f"
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user