From 0ef61eaf131888c873a2df1dccb04b34bb7e7383 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sun, 21 Aug 2016 11:32:17 +1200 Subject: Add bash prompt Git fixes into pdksh --- pdksh/pdkshrc.d/prompt.pdksh | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/pdksh/pdkshrc.d/prompt.pdksh b/pdksh/pdkshrc.d/prompt.pdksh index 71e952a0..2486373d 100644 --- a/pdksh/pdkshrc.d/prompt.pdksh +++ b/pdksh/pdkshrc.d/prompt.pdksh @@ -95,21 +95,19 @@ prompt() { fi branch=${branch##*/} + # Refresh index so e.g. git-diff-files(1) is accurate + git update-index --refresh >/dev/null + + # Collect symbols representing repository state typeset state - if ! git diff-files --quiet ; then - # Two exclamation marks, as that's how you get a literal "!" in - # a pdksh PS1 + git diff-files --quiet || state=${state}!! - fi - if ! git diff-index --cached --quiet HEAD ; then + git diff-index --cached --quiet HEAD || state=${state}+ - fi - if [[ -n $(git ls-files --others --exclude-standard) ]] ; then - state=${state}? - fi - if git rev-parse --verify refs/stash >/dev/null 2>&1 ; then + [[ -n $(git ls-files --others --exclude-standard) ]] && + state=${state}\? + git rev-parse --quiet --verify refs/stash >/dev/null && state=${state}^ - fi # Print the status in brackets; add a git: prefix only if there # might be another VCS prompt (because PROMPT_VCS is set) -- cgit v1.2.3 From 5ce5d0813c34ce919a7636ef65a673b40bed77ef Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sun, 21 Aug 2016 12:36:09 +1200 Subject: Port Bash Git prompt changes to pdksh --- pdksh/pdkshrc.d/prompt.pdksh | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/pdksh/pdkshrc.d/prompt.pdksh b/pdksh/pdkshrc.d/prompt.pdksh index 2486373d..f9dfa584 100644 --- a/pdksh/pdkshrc.d/prompt.pdksh +++ b/pdksh/pdkshrc.d/prompt.pdksh @@ -100,14 +100,30 @@ prompt() { # Collect symbols representing repository state typeset state + + # Upstream HEAD has commits after local HEAD; we're "behind" + (($(git rev-list --count 'HEAD..@{u}' 2>/dev/null) > 0)) && + state=${state}\< + + # Local HEAD has commits after upstream HEAD; we're "ahead" + (($(git rev-list --count '@{u}..HEAD' 2>/dev/null) > 0)) && + state=${state}\> + + # Tracked files are modified git diff-files --quiet || - state=${state}!! + state=${state}'!!' + + # Changes are staged git diff-index --cached --quiet HEAD || - state=${state}+ + state=${state}\+ + + # There are some untracked and unignored files [[ -n $(git ls-files --others --exclude-standard) ]] && state=${state}\? + + # There are stashed changes git rev-parse --quiet --verify refs/stash >/dev/null && - state=${state}^ + state=${state}\^ # Print the status in brackets; add a git: prefix only if there # might be another VCS prompt (because PROMPT_VCS is set) -- cgit v1.2.3