More shgit rework

- Use -q in git-symbolic-ref
- Improve ahead / behind count a bit by assigning it to positional
  parameters and getting rid of a conditional
This commit is contained in:
Lucas 2019-12-13 10:54:20 +00:00
parent e2a89e04b6
commit 8362f872f4

View File

@ -16,8 +16,7 @@ shgit()
gitdir=$(git rev-parse --git-dir 2>/dev/null) && [ -n "$gitdir" ] || gitdir=$(git rev-parse --git-dir 2>/dev/null) && [ -n "$gitdir" ] ||
return return
name=$(git symbolic-ref --short HEAD 2>/dev/null) if ! name=$(git symbolic-ref -q --short HEAD); then
if [ -z "$name" ]; then
name=$(git rev-parse --short HEAD 2>/dev/null) name=$(git rev-parse --short HEAD 2>/dev/null)
name=${hash:-?} name=${hash:-?}
fi fi
@ -37,14 +36,12 @@ shgit()
status= status=
[ -n "$(git status --porcelain)" ] && status=${SHGIT_SEP}* [ -n "$(git status --porcelain)" ] && status=${SHGIT_SEP}*
commits=$(git rev-list --left-right --count @{upstream}...HEAD \ IFS=" " set -- $(git rev-list --left-right --count \
2>/dev/null | tr "\t" ^) @{upstream}...HEAD 2>/dev/null)
if [ -n "$commits" ]; then commits=v${1:-0}^${2:-0}
commits=v$commits commits=${commits#v0}
commits=${commits#v0} commits=${commits%^0}
commits=${commits%^0} commits=${commits:+$SHGIT_SEP$commits}
commits=${commits:+$SHGIT_SEP$commits}
fi
printf "%s%s%s" "$SHGIT_BEGIN" "$name$rb$status$commits" "$SHGIT_END" printf "%s%s%s" "$SHGIT_BEGIN" "$name$rb$status$commits" "$SHGIT_END"
} }