commit afa712697fa8ed768f4811c5ee72758b70680ed8 parent b3232e15b3d4582581111891cc877c480f0ba418 Author: Kévin Le Gouguec <kevin.legouguec@gmail.com> Date: Sat, 17 Oct 2026 11:18:15 +0200 Move $? reporting to PS1 & unify dumb & smart prompts Diffstat:
| M | .bash_prompt | | | 43 | ++++++++++++++++++++++++++----------------- |
1 file changed, 26 insertions(+), 17 deletions(-)
diff --git a/.bash_prompt b/.bash_prompt @@ -96,43 +96,40 @@ __signal-no-newline () echo } -__write-epilogue () +__signal-rc () { local -ir rc=$1 local -r rc_hex=$(printf %02x ${rc}) - local -r stamp=$(printf '%(%T)T') - - __fontify '[ ' dim if ((rc)) then - __fontify '$?:' dim red __fontify ${rc_hex} bold red else - __fontify "\$?:${rc_hex}" dim + __fontify ${rc_hex} dim fi - - __fontify " | ${stamp} ]" dim - echo } __smart-term/set-ps1 () { + local -ir rc=$1 + PS1=$( BUILDING_PS=t - __fontify '\u' green + __fontify '[ ' dim + __signal-rc ${rc} + printf ' ' + __fontify '\u' dim green __show-hostname && { __fontify @ dim __fontify '\H' bold green } - printf ' ' - __fontify '\w' bold blue - printf '\\n' + __fontify ' ]' dim + printf '\\n' __fontify '\$' dim printf ' ' ) @@ -144,8 +141,7 @@ __smart-term/refresh () __set-title __signal-no-newline - __write-epilogue ${rc} - __smart-term/set-ps1 + __smart-term/set-ps1 ${rc} } __smart-term/init () @@ -167,16 +163,29 @@ __smart-term/init () tty -s && stty stop '' } +__dumb-term/set-ps1 () +{ + local -ir rc=$1 + + PS1=$( + BUILDING_PS=t + __fontify '[ ' dim + __signal-rc ${rc} + printf ' ' + __fontify '\W' bold blue + __fontify ' ]\$ ' dim + ) +} + __dumb-term/refresh () { local -ir rc=$? - __write-epilogue ${rc} + __dumb-term/set-ps1 ${rc} } __dumb-term/init () { PROMPT_COMMAND=__dumb-term/refresh - PS1='\W\$ ' # I configure 'M-x shell' to use TERM=dumb-emacs-ansi; empirically # this makes Bash emit this bracketed paste sequence…