Fix shgit shell style and reenable it
This commit is contained in:
parent
9b49b33642
commit
ba76c45683
@ -30,11 +30,17 @@ if [ -d ~/local/man ]; then
|
||||
alias man="/usr/bin/man -m ~/local/man"
|
||||
fi
|
||||
|
||||
PS1=
|
||||
if [ -f ~/code/lucas/env/utils/shgit ]; then
|
||||
. ~/code/lucas/env/utils/shgit
|
||||
export PS1='$(shgit)'
|
||||
fi
|
||||
|
||||
case $SHELL in
|
||||
/bin/mksh)
|
||||
PS1='${HOSTNAME:=$(hostname -s)}\$ '
|
||||
PS1=$PS1'${HOSTNAME:=$(hostname -s)}\$ '
|
||||
;;
|
||||
*) PS1='\h\$ '
|
||||
*) PS1=$PS1'\h\$ '
|
||||
;;
|
||||
esac
|
||||
export PS1
|
||||
|
30
utils/shgit
30
utils/shgit
@ -1,4 +1,4 @@
|
||||
# env
|
||||
# shgit
|
||||
# Written in 2019 by Lucas
|
||||
# CC0 1.0 Universal/Public domain - No rights reserved
|
||||
#
|
||||
@ -9,20 +9,24 @@
|
||||
# Dedication along with this software. If not, see
|
||||
# <http://creativecommons.org/publicdomain/zero/1.0/>.
|
||||
|
||||
shgit() {
|
||||
if ! gitdir=$(git rev-parse --git-dir 2>/dev/null) \
|
||||
|| [ -z "$gitdir" ]; then
|
||||
return
|
||||
fi
|
||||
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)
|
||||
hash=$(git rev-parse --short HEAD 2>/dev/null)
|
||||
name=${symbolic:-${hash:-"?"}}
|
||||
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="REBASE"
|
||||
rb="${SHGIT_SEP}REBASE"
|
||||
read -r name <"$rbdir/head-name"
|
||||
name=${name##*/}
|
||||
[ -f "$rbdir/interactive" ] && rb="$rb-i"
|
||||
@ -32,9 +36,7 @@ shgit() {
|
||||
fi
|
||||
|
||||
status=
|
||||
if [ -z "$(git status --porcelain)" ]; then
|
||||
status="*"
|
||||
fi
|
||||
[ -n "$(git status --porcelain)" ] && status="${SHGIT_SEP}*"
|
||||
|
||||
commits=$(git rev-list --left-right --count @{upstream}...HEAD \
|
||||
2>/dev/null | {
|
||||
@ -42,8 +44,8 @@ shgit() {
|
||||
IFS=" " read -r behind ahead
|
||||
[ ${behind:-0} -gt 0 ] && t=$t"v$behind"
|
||||
[ ${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"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user