stole some more code from von

Signed-off-by: fbt <fbt@fleshless.org>
This commit is contained in:
Jack L. Frost 2017-11-09 15:47:57 +03:00
parent f9fdcd4b16
commit 8ec75e7abe
1 changed files with 23 additions and 26 deletions

View File

@ -59,39 +59,36 @@ precmd.is_git_repo() {
}
precmd.git() {
declare git_unstaged git_untracked git_status_short git_status_colour git_prompt_msg
declare git_branch_info git_unstaged git_untracked git_status_short git_status_colour git_prompt_msg
if [[ -f .novcsprompt ]]; then
return 0
fi
[[ -f .novcsprompt ]] && return 0
precmd.is_git_repo || return 0
if precmd.is_git_repo; then
git_current_branch=$(git rev-parse --abbrev-ref HEAD)
while IFS= read -r line; do
case $line in
' M'*|A*|D*) git_unstaged=1;;
\?\?*) git_untracked=1;;
esac
done < <( git status --short )
declare line
while IFS= read -r line; do
[[ $line[1,2] == '##' ]] && git_branch_info=$line[4,-1]
[[ $line[1,2] == '??' ]] && (( git_untracked++ ))
[[ $line[1,2] =~ .[MD] ]] && (( git_unstaged++ ))
done < <(git status --porcelain -bu 2>/dev/null)
(( git_unstaged )) && {
git_status_short+='c'
git_status_colour='red'
}
git_branch_name=${git_branch_info%%...*}
(( git_untracked )) && {
git_status_short+='f'
git_status_colour='red'
}
(( git_unstaged )) && {
git_status_short+='c'
git_status_colour='red'
}
git_status_short=${git_status_short:-"ok"}
git_status_colour=${git_status_colour:-"green"}
(( git_untracked )) && {
git_status_short+='f'
git_status_colour='red'
}
git_prompt_msg="(%F{cyan}$git_current_branch%f[%F{$git_status_colour}${git_status_short}%f]) "
git_status_short=${git_status_short:-"ok"}
git_status_colour=${git_status_colour:-"green"}
printf '%s' $git_prompt_msg
fi
git_prompt_msg="(%F{cyan}$git_branch_name%f[%F{$git_status_colour}${git_status_short}%f]) "
printf '%s' $git_prompt_msg
}
rprompt() {