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
1 changed files with 7 additions and 10 deletions

View File

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