40 lines
1.2 KiB
Bash
Executable file
40 lines
1.2 KiB
Bash
Executable file
#!/bin/bash
|
|
{ type -p git && git rev-parse --git-dir; } >/dev/null 2>&1 || exit $?
|
|
# see https://git-scm.com/docs/git-status for more information
|
|
# these are status information from the local git index
|
|
|
|
CAH=0 CBH=0
|
|
D=0 A=0 M=0 R=0 U=0 I=0
|
|
while read -r format state values; do
|
|
case ${format} in
|
|
\#)
|
|
case ${state} in
|
|
branch.oid) COMMIT="${values}" ;;
|
|
branch.head) BRANCH="${values}" ;;
|
|
branch.upstream) UPSTREAM="${values}" ;;
|
|
branch.ab) read -r CAH CBD <<<"${values}" ;;
|
|
esac
|
|
;;
|
|
1) (( ${state:0:1}++ )) ;;
|
|
2) (( ${state:0:1}++ )) ;;
|
|
\?) (( U++ )) ;;
|
|
\!) (( I++ )) ;;
|
|
esac
|
|
done < <(git status --porcelain=2 --branch)
|
|
|
|
[[ ${CAH} -gt 0 ]] && echo -n "\\[\\e[0;32m\\]<\\[\\e[0m\\]${CAH} ";
|
|
[[ ${CBH} -gt 0 ]] && echo -n "\\[\\e[0;31m\\]>\\[\\e[0m\\]${CBH} ";
|
|
|
|
|
|
[[ ${M} -gt 0 ]] && _BRANCH="\\[\\e[0;31m\\]" || _BRANCH="\\[\\e[0;32m\\]"
|
|
if [[ "${BRANCH}" == "(detached)" ]]; then
|
|
BRANCH="{${COMMIT:0:8}}"
|
|
else
|
|
BRANCH="(${BRANCH})"
|
|
fi
|
|
echo -n "${_BRANCH}${BRANCH}\\[\\e[0m\\] "
|
|
|
|
[[ ${A} -gt 0 ]] && echo -n "\\[\\e[0;32m\\]+\\[\\e[0m\\]${A} ";
|
|
[[ ${D} -gt 0 ]] && echo -n "\\[\\e[0;31m\\]-\\[\\e[0m\\]${D} ";
|
|
[[ ${M} -gt 0 ]] && echo -n "\\[\\e[0;35m\\]~\\[\\e[0m\\]${M} ";
|
|
[[ ${U} -gt 0 ]] && echo -n "\\[\\e[0;33m\\]?\\[\\e[0m\\]${U} ";
|