aboutsummaryrefslogtreecommitdiff
path: root/pdksh
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-09-20 21:20:53 +1200
committerTom Ryder <tom@sanctum.geek.nz>2016-09-20 21:20:53 +1200
commit48cd8d3761c39bbe841f6aa3a31e018c4719388c (patch)
treeebc64a5bd4046029955bdea5242569315c72acde /pdksh
parentMerge branch 'master' into openbsd (diff)
downloaddotfiles-48cd8d3761c39bbe841f6aa3a31e018c4719388c.tar.gz
dotfiles-48cd8d3761c39bbe841f6aa3a31e018c4719388c.zip
Fork bash prompt changes to pdksh
Diffstat (limited to 'pdksh')
-rw-r--r--pdksh/pdkshrc.d/prompt.pdksh209
1 files changed, 104 insertions, 105 deletions
diff --git a/pdksh/pdkshrc.d/prompt.pdksh b/pdksh/pdkshrc.d/prompt.pdksh
index a75618be..fd99c5f7 100644
--- a/pdksh/pdkshrc.d/prompt.pdksh
+++ b/pdksh/pdkshrc.d/prompt.pdksh
@@ -31,46 +31,43 @@ prompt() {
# Add terminating "$" or "#" sign
PS1=$PS1'\$'
- # Count available colors
- typeset -i colors
- colors=$( {
- tput Co || tput colors
- } 2>/dev/null )
-
- # Prepare reset code
- typeset reset
- reset=$( {
- tput me || tput sgr0
- } 2>/dev/null )
-
- # Decide prompt color formatting based on color availability
- typeset format
-
- # Check if we have non-bold bright yellow available
- if ((colors >= 16)) ; then
- format=$( {
- : "${PROMPT_COLOR:=11}"
- tput setaf "$PROMPT_COLOR" ||
- tput setaf "$PROMPT_COLOR" 0 0 ||
- tput AF "$PROMPT_COLOR" ||
- tput AF "$PROMPT_COLOR" 0 0
- } 2>/dev/null )
-
- # If we have only eight colors, use bold yellow
- elif ((colors >= 8)) ; then
- format=$( {
- : "${PROMPT_COLOR:=3}"
- tput setaf "$PROMPT_COLOR" ||
- tput AF "$PROMPT_COLOR"
- tput bold || tput md
- } 2>/dev/null )
-
- # Otherwise, we just try bold
- else
- format=$( {
- tput bold || tput md
- } 2>/dev/null )
- fi
+ # Declare variables to contain terminal control strings
+ typeset format reset
+
+ # Disregard output and error from these tput(1) calls
+ {
+ # Count available colors
+ typeset -i colors
+ colors=$(tput colors || tput Co)
+
+ # Prepare reset code
+ reset=$(tput sgr0 || tput me)
+
+ # Check if we have non-bold bright green available
+ if ((colors >= 16)) ; then
+ format=$(
+ : "${PROMPT_COLOR:=11}"
+ tput setaf "$PROMPT_COLOR" ||
+ tput setaf "$PROMPT_COLOR" 0 0 ||
+ tput AF "$PROMPT_COLOR" ||
+ tput AF "$PROMPT_COLOR" 0 0
+ )
+
+ # If we have only eight colors, use bold green
+ elif ((colors >= 8)) ; then
+ format=$(
+ : "${PROMPT_COLOR:=3}"
+ tput setaf "$PROMPT_COLOR" ||
+ tput AF "$PROMPT_COLOR"
+ tput bold || tput md
+ )
+
+ # Otherwise, we just try bold
+ else
+ format=$(tput bold || tput md)
+ fi
+
+ } >/dev/null 2>&1
# String it all together
PS1='\['"$format"'\]'"$PS1"'\['"$reset"'\] '
@@ -81,75 +78,77 @@ prompt() {
# Git prompt function
git)
- # Bail if we're not in a work tree--or, implicitly, if we don't
- # have git(1).
- typeset iswt
- iswt=$(git rev-parse --is-inside-work-tree 2>/dev/null)
- [[ $iswt = true ]] || return
-
- # Refresh index so e.g. git-diff-files(1) is accurate
- git update-index --refresh >/dev/null 2>&1
-
- # Find a local branch, remote branch, or tag (annotated or not), or
- # failing all of that just show the short commit ID, in that order
- # of preference; if none of that works, bail out
- typeset name
- name=$( {
- git symbolic-ref --quiet HEAD ||
- git describe --tags --exact-match HEAD ||
- git rev-parse --short HEAD
- } 2>/dev/null) || return
- name=${name##*/}
- [[ -n $name ]] || return
-
- # Check various files in .git to flag processes
- typeset proc
- [[ -d .git/rebase-merge || -d .git/rebase-apply ]] &&
- proc=${proc:+$proc,}'REBASE'
- [[ -f .git/MERGE_HEAD ]] &&
- proc=${proc:+$proc,}'MERGE'
- [[ -f .git/CHERRY_PICK_HEAD ]] &&
- proc=${proc:+$proc,}'PICK'
- [[ -f .git/REVERT_HEAD ]] &&
- proc=${proc:+$proc,}'REVERT'
- [[ -f .git/BISECT_LOG ]] &&
- proc=${proc:+$proc,}'BISECT'
-
- # Collect symbols representing repository state
- typeset state
-
- # Upstream HEAD has commits after local HEAD; we're "behind"
- typeset -i behind
- behind=$(git rev-list --count 'HEAD..@{u}' 2>/dev/null)
- ((behind)) && state=${state}'<'
-
- # Local HEAD has commits after upstream HEAD; we're "ahead"
- typeset -i ahead
- ahead=$(git rev-list --count '@{u}..HEAD' 2>/dev/null)
- ((ahead)) && state=${state}'>'
-
- # Tracked files are modified; double exclamation mark because
- # that's how you get a literal one in pdksh PS1
- git diff-files --no-ext-diff --quiet ||
- state=${state}'!!'
-
- # Changes are staged
- git diff-index --cached --no-ext-diff --quiet HEAD 2>/dev/null ||
- state=${state}'+'
-
- # There are some untracked and unignored files
- git ls-files --directory --error-unmatch --exclude-standard \
- --no-empty-directory --others -- ':/*' >/dev/null 2>&1 &&
- state=${state}'?'
-
- # There are stashed changes
- git rev-parse --quiet --verify refs/stash >/dev/null &&
- state=${state}'^'
+
+ # Wrap as compound command; we don't want to see output from any of
+ # these git(1) calls
+ {
+ # Bail if we're not in a work tree--or, implicitly, if we don't
+ # have git(1).
+ [[ -n $(git rev-parse --is-inside-work-tree) ]] ||
+ return
+
+ # Refresh index so e.g. git-diff-files(1) is accurate
+ git update-index --refresh
+
+ # Find a local branch, remote branch, or tag (annotated or
+ # not), or failing all of that just show the short commit ID,
+ # in that order of preference; if none of that works, bail out
+ typeset name
+ name=$(
+ git symbolic-ref --quiet HEAD ||
+ git describe --tags --exact-match HEAD ||
+ git rev-parse --short HEAD
+ ) || return
+ name=${name##*/}
+ [[ -n $name ]] || return
+
+ # Check various files in .git to flag processes
+ typeset proc
+ [[ -d .git/rebase-merge || -d .git/rebase-apply ]] &&
+ proc=${proc:+"$proc",}'REBASE'
+ [[ -f .git/MERGE_HEAD ]] &&
+ proc=${proc:+"$proc",}'MERGE'
+ [[ -f .git/CHERRY_PICK_HEAD ]] &&
+ proc=${proc:+"$proc",}'PICK'
+ [[ -f .git/REVERT_HEAD ]] &&
+ proc=${proc:+"$proc",}'REVERT'
+ [[ -f .git/BISECT_LOG ]] &&
+ proc=${proc:+"$proc",}'BISECT'
+
+ # Collect symbols representing repository state
+ typeset state
+
+ # Upstream HEAD has commits after local HEAD; we're "behind"
+ (($(git rev-list --count 'HEAD..@{u}'))) &&
+ state=${state}'<'
+
+ # Local HEAD has commits after upstream HEAD; we're "ahead"
+ (($(git rev-list --count '@{u}..HEAD'))) &&
+ state=${state}'>'
+
+ # Tracked files are modified
+ git diff-files --no-ext-diff --quiet ||
+ state=${state}'!!'
+
+ # Changes are staged
+ git diff-index --cached --no-ext-diff --quiet HEAD ||
+ state=${state}'+'
+
+ # There are some untracked and unignored files
+ git ls-files --directory --error-unmatch --exclude-standard \
+ --no-empty-directory --others -- ':/*' &&
+ state=${state}'?'
+
+ # There are stashed changes
+ git rev-parse --quiet --verify refs/stash &&
+ state=${state}'^'
+
+ } >/dev/null 2>&1
# Print the status in brackets; add a git: prefix only if there
# might be another VCS prompt (because PROMPT_VCS is set)
printf '(%s%s%s%s)' \
- "${PROMPT_VCS:+git:}" "$name" "${proc:+:$proc}" "$state"
+ "${PROMPT_VCS:+git:}" "$name" "${proc:+:"$proc"}" "$state"
;;
# Revert to simple inexpensive prompts