Skip to content
Permalink
1afeb7462a
Switch branches/tags
Go to file
 
 
Cannot retrieve contributors at this time
executable file 67 lines (62 sloc) 1.42 KB
#!/usr/bin/env sh
# Output a succinct, one-line Git status
#
# E.g.:
# 1ac744a5522d UUAM? master+1-5 origin/master
#
# Usage:
# git prompt
# git-prompt /path/to/repo
color=""
while getopts c: opt; do
case $opt in
c) color="$OPTARG";;
esac
done
shift $(( OPTIND - 1 ))
tgtdir="${1:-$PWD}"
git \
-C "$tgtdir" \
--no-optional-locks \
status \
--porcelain=v2 \
--branch \
2>/dev/null \
| awk -v color="$color" '
BEGIN {
if (color == "ansi") {
_reset = "\033[0m"
_red = "\033[31m"
_green = "\033[32;1m"
_yellow = "\033[33;1m"
} else if (color == "tmux") {
_reset = "#[fg=terminal]"
_red = "#[fg=red]"
_green = "#[fg=green,bold]"
_yellow = "#[fg=yellow,bold]"
}
}
/^# branch\.oid/ { sha=substr($3, 0, 12) }
/^# branch\.head/ { branch=$3 }
/^# branch\.upstream/ { upstream=$3 }
/^# branch\.ab/ {
a = $3 != "+0" ? $3 : ""
b = $4 != "-0" ? $4 : ""
}
/^\?/ { untracked="?" }
/^[0-9] [A-Z]. / { added="A" }
/^[0-9] .[A-Z] / { modified="M" }
/^u UU/ { conflicts="UU" }
END {
print (\
_reset sha,
_red conflicts \
_green added \
_red modified \
_yellow untracked ,
_reset branch \
_green a \
_red b,
_reset)
}
'