52 lines
1.5 KiB
Plaintext
52 lines
1.5 KiB
Plaintext
# shgit
|
|
# Written in 2019 by Lucas
|
|
# CC0 1.0 Universal/Public domain - No rights reserved
|
|
#
|
|
# To the extent possible under law, the author(s) have dedicated all
|
|
# copyright and related and neighboring rights to this software to the
|
|
# public domain worldwide. This software is distributed without any
|
|
# warranty. You should have received a copy of the CC0 Public Domain
|
|
# Dedication along with this software. If not, see
|
|
# <http://creativecommons.org/publicdomain/zero/1.0/>.
|
|
|
|
shgit()
|
|
{
|
|
: ${SHGIT_BEGIN:=} ${SHGIT_END:= } ${SHGIT_SEP:=:}
|
|
|
|
gitdir=$(git rev-parse --git-dir 2>/dev/null) && [ -n "$gitdir" ] ||
|
|
return
|
|
|
|
symbolic=$(git symbolic-ref --short HEAD 2>/dev/null)
|
|
name=${symbolic:-}
|
|
if [ -z "$name" ]; then
|
|
hash=$(git rev-parse --short HEAD 2>/dev/null)
|
|
name=${hash:-"?"}
|
|
fi
|
|
|
|
rb=
|
|
rbdir="$gitdir/rebase-merge"
|
|
if [ -d "$rbdir" ]; then
|
|
rb="${SHGIT_SEP}REBASE"
|
|
read -r name <"$rbdir/head-name"
|
|
name=${name##*/}
|
|
[ -f "$rbdir/interactive" ] && rb="$rb-i"
|
|
rbcount=$(wc -l <"$rbdir/done")
|
|
read -r rbtotal <"$rbdir/end"
|
|
rb="$rb ${rbcount##* }/$rbtotal"
|
|
fi
|
|
|
|
status=
|
|
[ -n "$(git status --porcelain)" ] && status="${SHGIT_SEP}*"
|
|
|
|
commits=$(git rev-list --left-right --count @{upstream}...HEAD \
|
|
2>/dev/null | {
|
|
t=
|
|
IFS=" " read -r behind ahead
|
|
[ ${behind:-0} -gt 0 ] && t=$t"v$behind"
|
|
[ ${ahead:-0} -gt 0 ] && t=$t"^$ahead"
|
|
[ -n "$t" ] && printf "%s" "$SHGIT_SEP" "$t"
|
|
})
|
|
|
|
printf "%s%s%s" "$SHGIT_BEGIN" "$name$rb$status$commits" "$SHGIT_END"
|
|
}
|