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