More robust parsing of branch name

This commit is contained in:
Felix Van der Jeugt 2020-09-22 11:04:07 +02:00
parent d231f378f5
commit 59a98addb4
No known key found for this signature in database
GPG Key ID: 58B209295023754D

2
yashrc
View File

@ -20,7 +20,7 @@ ks() { s="$?" ; $* ; return "$s" ; }
prompt_git() {
porcelain="$(git status --branch --porcelain 2>/dev/null)"
if test "$?" = 0; then
local branch="$(printf '%s' "$porcelain" | sed -n '1s/## \([^.]*\)\.\.\..*/\1/p')"
local branch="$(printf '%s' "$porcelain" | sed -n 's/\.\.\..*//;1s/## //p')"
local behind="$(printf '%s' "$porcelain" | sed -n '1s/## .*behind \([0-9]*\).*/⇃\1/p')"
local ahead="$(printf '%s' "$porcelain" | sed -n '1s/## .*ahead \([0-9]*\).*/↿\1/p')"
local status="$({ echo OK; printf '%s' "$porcelain" | sed '/##/d;s/\(..\).*/\1/'; } | tail -1)"