dotfiles

Obligatory dotfiles repo
git clone git://git.danielmoch.com/dotfiles.git
Log | Files | Refs

commit b8d0eeacef929eee315e50bc3152a18a983d8bc7
parent bb94a2dac574ab22417490991c7f1cbcfcec7849
Author: Daniel Moch <daniel@danielmoch.com>
Date:   Sat, 14 Dec 2019 11:04:25 -0500

Fix handling of bare repos in $PS1

Diffstat:
M.shrc.d/ps1.sh | 36++++++++++++++++++++++++------------
1 file changed, 24 insertions(+), 12 deletions(-)

diff --git a/.shrc.d/ps1.sh b/.shrc.d/ps1.sh @@ -11,21 +11,33 @@ __ps1() { if type git > /dev/null 2>&1 then - if git rev-parse --show-toplevel > /dev/null 2>&1 + workdir=$(git rev-parse --is-inside-work-tree 2>/dev/null) + if [ $? -eq 0 ] then - gitref=$(git rev-parse --abbrev-ref HEAD 2>/dev/null) - [ $? -ne 0 ] && gitref="GIT: empty" - [ "$gitref" = HEAD ] && gitref=\($(git rev-parse --short HEAD)\) - git diff --no-ext-diff --quiet || status="*" - git diff --no-ext-diff --cached --quiet || status="$status+" - if [ "$(git config --bool sh.showUntrackedFiles)" != "false" ] && - git ls-files --others --exclude-standard --directory \ - --no-empty-directory --error-unmatch -- ':/*' >/dev/null 2>/dev/null + if [ "$workdir" = "false" ] then - status="$status%" + bare=$(git rev-parse --is-bare-repository 2>/dev/null) + if [ $? -ne 0 ] + then + echo + else + echo " (GIT: bare)" + fi + else + gitref=$(git rev-parse --abbrev-ref HEAD 2>/dev/null) + [ $? -ne 0 ] && gitref="GIT: empty" + [ "$gitref" = HEAD ] && gitref=\($(git rev-parse --short HEAD)\) + git diff --no-ext-diff --quiet || status="*" + git diff --no-ext-diff --cached --quiet || status="$status+" + if [ "$(git config --bool sh.showUntrackedFiles)" != "false" ] && + git ls-files --others --exclude-standard --directory \ + --no-empty-directory --error-unmatch -- ':/*' >/dev/null 2>/dev/null + then + status="$status%" + fi + [ -n "$status" ] && gitref="$gitref $status" + echo " ($gitref)" fi - [ -n "$status" ] && gitref="$gitref $status" - echo " ($gitref)" else echo fi