Fix shgit shell style and reenable it

This commit is contained in:
Lucas 2019-12-09 11:03:41 +00:00
parent 9b49b33642
commit ba76c45683
2 changed files with 24 additions and 16 deletions

View File

@ -30,11 +30,17 @@ if [ -d ~/local/man ]; then
alias man="/usr/bin/man -m ~/local/man" alias man="/usr/bin/man -m ~/local/man"
fi fi
PS1=
if [ -f ~/code/lucas/env/utils/shgit ]; then
. ~/code/lucas/env/utils/shgit
export PS1='$(shgit)'
fi
case $SHELL in case $SHELL in
/bin/mksh) /bin/mksh)
PS1='${HOSTNAME:=$(hostname -s)}\$ ' PS1=$PS1'${HOSTNAME:=$(hostname -s)}\$ '
;; ;;
*) PS1='\h\$ ' *) PS1=$PS1'\h\$ '
;; ;;
esac esac
export PS1 export PS1

View File

@ -1,4 +1,4 @@
# env # shgit
# Written in 2019 by Lucas # Written in 2019 by Lucas
# CC0 1.0 Universal/Public domain - No rights reserved # CC0 1.0 Universal/Public domain - No rights reserved
# #
@ -9,20 +9,24 @@
# Dedication along with this software. If not, see # Dedication along with this software. If not, see
# <http://creativecommons.org/publicdomain/zero/1.0/>. # <http://creativecommons.org/publicdomain/zero/1.0/>.
shgit() { shgit()
if ! gitdir=$(git rev-parse --git-dir 2>/dev/null) \ {
|| [ -z "$gitdir" ]; then : ${SHGIT_BEGIN:=} ${SHGIT_END:= } ${SHGIT_SEP:=:}
return
fi gitdir=$(git rev-parse --git-dir 2>/dev/null) && [ -n "$gitdir" ] ||
return
symbolic=$(git symbolic-ref --short HEAD 2>/dev/null) symbolic=$(git symbolic-ref --short HEAD 2>/dev/null)
hash=$(git rev-parse --short HEAD 2>/dev/null) name=${symbolic:-}
name=${symbolic:-${hash:-"?"}} if [ -z "$name" ]; then
hash=$(git rev-parse --short HEAD 2>/dev/null)
name=${hash:-"?"}
fi
rb= rb=
rbdir="$gitdir/rebase-merge" rbdir="$gitdir/rebase-merge"
if [ -d "$rbdir" ]; then if [ -d "$rbdir" ]; then
rb="REBASE" rb="${SHGIT_SEP}REBASE"
read -r name <"$rbdir/head-name" read -r name <"$rbdir/head-name"
name=${name##*/} name=${name##*/}
[ -f "$rbdir/interactive" ] && rb="$rb-i" [ -f "$rbdir/interactive" ] && rb="$rb-i"
@ -32,9 +36,7 @@ shgit() {
fi fi
status= status=
if [ -z "$(git status --porcelain)" ]; then [ -n "$(git status --porcelain)" ] && status="${SHGIT_SEP}*"
status="*"
fi
commits=$(git rev-list --left-right --count @{upstream}...HEAD \ commits=$(git rev-list --left-right --count @{upstream}...HEAD \
2>/dev/null | { 2>/dev/null | {
@ -42,8 +44,8 @@ shgit() {
IFS=" " read -r behind ahead IFS=" " read -r behind ahead
[ ${behind:-0} -gt 0 ] && t=$t"v$behind" [ ${behind:-0} -gt 0 ] && t=$t"v$behind"
[ ${ahead:-0} -gt 0 ] && t=$t"^$ahead" [ ${ahead:-0} -gt 0 ] && t=$t"^$ahead"
printf "%s" "$t" [ -n "$t" ] && printf "%s" "$SHGIT_SEP" "$t"
}) })
printf "%s" "$name${rb:+:$rb}${status:+:$status}${commits:+:$commits}" printf "%s%s%s" "$SHGIT_BEGIN" "$name$rb$status$commits" "$SHGIT_END"
} }