aboutsummaryrefslogtreecommitdiff
path: root/ksh
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-12-27 01:45:20 +1300
committerTom Ryder <tom@sanctum.geek.nz>2016-12-27 01:45:20 +1300
commitce14fceb1080452504184b2e4d5fef142bc5fce5 (patch)
treeec422ddb5c18e5d9b03d757debd76939cf57bffa /ksh
parentAdd an issue (diff)
downloaddotfiles-ce14fceb1080452504184b2e4d5fef142bc5fce5.tar.gz
dotfiles-ce14fceb1080452504184b2e4d5fef142bc5fce5.zip
Put exit value of previous command in ksh PS1
Found a way to do this that seems to work in all the KSHes I've tried
Diffstat (limited to 'ksh')
-rw-r--r--ksh/kshrc.d/prompt.ksh18
1 files changed, 7 insertions, 11 deletions
diff --git a/ksh/kshrc.d/prompt.ksh b/ksh/kshrc.d/prompt.ksh
index fe1f0273..99e193b2 100644
--- a/ksh/kshrc.d/prompt.ksh
+++ b/ksh/kshrc.d/prompt.ksh
@@ -18,20 +18,17 @@ function prompt {
PS1=$PS1'$USER@${HOSTNAME%%.*}:'
fi
- # Add sub-commands; working directory with ~ abbreviation, VCS,
- # and job count
- PS1=$PS1'$(prompt pwd)$(prompt vcs)$(prompt job)'
-
- # If this is PDKSH, add the exit code of the previous command; this
- # doesn't seem to work on ksh93, probably different timing for when
- # $? is set
- case $KSH_VERSION in
- *'PD KSH'*) PS1=$PS1'$(prompt ret "$?")'
- esac
+ # Add sub-commands; working directory with ~ abbreviation, VCS, job
+ # count, and previous command return value
+ PS1=$PS1'$(prompt pwd)$(prompt vcs)$(prompt job)$(prompt ret)'
# Add prefix and suffix
PS1='${PROMPT_PREFIX}'$PS1'${PROMPT_SUFFIX}'
+ # Add a wrapper around the prompt as determined so far so that the
+ # return value from the previous command doesn't get lost
+ PS1='$(ret=$?;printf %s "'"$PS1"'")'
+
# Add terminating "$" or "#" sign
PS1=$PS1'\$'
@@ -193,7 +190,6 @@ function prompt {
# Show return status of previous command in angle brackets, if not zero
ret)
- typeset ret=$2
((ret)) && printf '<%u>' "$ret"
;;