aboutsummaryrefslogtreecommitdiff
path: root/pdksh
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-08-14 00:16:29 +1200
committerTom Ryder <tom@sanctum.geek.nz>2016-08-14 00:16:29 +1200
commit6b00d43d7413309b8b5e8c5bd3dffe5fed694a8b (patch)
tree4411bd18334f0d82160b7521c459b1cb86101744 /pdksh
parentMerge branch 'master' into openbsd (diff)
downloaddotfiles-6b00d43d7413309b8b5e8c5bd3dffe5fed694a8b.tar.gz
dotfiles-6b00d43d7413309b8b5e8c5bd3dffe5fed694a8b.zip
Port Git prompt function from Bash to pdksh
Diffstat (limited to 'pdksh')
-rw-r--r--pdksh/pdkshrc.d/prompt.pdksh49
1 files changed, 49 insertions, 0 deletions
diff --git a/pdksh/pdkshrc.d/prompt.pdksh b/pdksh/pdkshrc.d/prompt.pdksh
index d261b90d..c3db782b 100644
--- a/pdksh/pdkshrc.d/prompt.pdksh
+++ b/pdksh/pdkshrc.d/prompt.pdksh
@@ -18,6 +18,7 @@ prompt() {
# Set up prompt, including optional PROMPT_PREFIX and PROMPT_SUFFIX
# variables
PS1='[\u@\h:\w]'
+ PS1=$PS1'$(prompt vcs)'
PS1=$PS1'$(prompt job)'
PS1='${PROMPT_PREFIX}'$PS1
PS1=$PS1'${PROMPT_SUFFIX}'
@@ -76,6 +77,44 @@ prompt() {
PS4='+<$?> $LINENO:'
;;
+ # Git prompt function
+ git)
+ # Bail if we have no git(1)
+ if ! hash git 2>/dev/null ; then
+ return 1
+ fi
+
+ # Attempt to determine git branch, bail if we can't
+ typeset branch
+ branch=$( {
+ git symbolic-ref --quiet HEAD ||
+ git rev-parse --short HEAD
+ } 2>/dev/null )
+ if [[ ! -n $branch ]] ; then
+ return 1
+ fi
+ branch=${branch##*/}
+
+ typeset state
+ if ! git diff-files --quiet ; then
+ # Two exclamation marks, as that's how you get a literal "!" in
+ # a pdksh PS1
+ state=${state}!!
+ fi
+ if ! git diff-index --cached --quiet HEAD ; then
+ 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
+ state=${state}^
+ fi
+
+ # Print the status in brackets with a git: prefix
+ printf '(git:%s%s)' "${branch:-unknown}" "$state"
+ ;;
+
# Revert to simple inexpensive prompts
off)
PS1='\$ '
@@ -84,6 +123,16 @@ prompt() {
PS4='+ '
;;
+ # VCS wrapper prompt function; print the first relevant prompt, if any
+ vcs)
+ typeset vcs
+ for vcs in "${PROMPT_VCS[@]:-git}" ; do
+ if prompt "$vcs" ; then
+ return
+ fi
+ done
+ ;;
+
# Show the count of background jobs in curly brackets, if not zero
job)
typeset -i jobc