Alexander Hall <[email protected]> writes:
[...]
> I'm pretty sure this messes up $? at the prompt. Try:
>
> false
> echo $?
>
> You could circumvent this by saving $? at the beginning of the function and
> returning it at the end.
Here's an excerpt of my .kshrc. The '$' is printed in red if the last
command failed, $? is preserved in case I want to know the exact value.
---
_nc=$(tput sgr0)
_red=$(tput setaf 1)
---
_ps1_err () {
local _rc=$?
[ "$_rc" -ne 0 ] && printf %s "$_red"
return "$_rc"
}
PS1='\h \w\[$(_ps1_err)\]\$\[$_nc\] '
---
--
jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF DDCC 0DFA 74AE 1524 E7EE