dotfiles

🎜 Clone'em, tweak'em, stick'em in your $HOME 🎝
git clone https://git.kevinlegouguec.net/dotfiles
Log | Files | Refs | README

commit 59eb42836441403aceab424c21bf6044a2b85728
parent 00cd46e1e52937fdd97c5fee89c4e6a7aff76a06
Author: KΓ©vin Le Gouguec <kevin.legouguec@gmail.com>
Date:   Sat, 15 Aug 2026 21:49:31 +0200

Add 'USER@HOST DIR' back to PS1

So that ^L re-draws this information.

While in there,

* always print exit code; keep it dim if zero,
* since there's always a full line "wasted" now, might as well stick a
timestamp,
* update findings about bracketed-paste snag.

Diffstat:
M.bash_prompt | 89+++++++++++++++++++++++++++++++++++++++++--------------------------------------
1 file changed, 46 insertions(+), 43 deletions(-)

diff --git a/.bash_prompt b/.bash_prompt @@ -25,20 +25,16 @@ __have-gitprompt () test -f /usr/lib/git-core/git-sh-prompt } -__ps1-pwd () -{ - # Empirically, no need to escape slashes in $HOME: Bash seems to - # parse ${VAR/#PAT/REP} by (1) splitting VAR, PAT & REP (2) *then* - # expanding PAT? - echo "${PWD/#${HOME}/\~}" -} - __set-title () { local title=${USER} + __show-hostname && title+=@${HOSTNAME} - title+=: - title+=$(__ps1-pwd) + + # Empirically, no need to escape slashes in $HOME: Bash seems to + # parse ${VAR/#PAT/REP} by (1) splitting VAR, PAT & REP (2) *then* + # expanding PAT? + title+=:${PWD/#${HOME}/\~} # Cf. console_codes(4): # @@ -120,39 +116,51 @@ __signal-no-newline () echo } -__signal-rc () +__write-epilogue () { local -ir rc=$1 - ((rc)) || return + 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 + fi - __fontify '$?: ' dim red - __fontify ${rc} bold red + __fontify " | ${stamp} ]" dim echo } -__write-context () +__smart-term/set-ps1 () { - # Decided to remove things off PS1 & print them directly instead, - # on a whim. No way to expand backslash sequences outside PS𝓃(?) - # so reimplement things like \w's s/$HOME/~. + PS1=$( + BUILDING_PS=t + __fontify '\u' green - __fontify "${USER}" green + __show-hostname && { + __fontify @ dim + __fontify '\H' bold green + } - __show-hostname && { - __fontify @ dim - __fontify "${HOSTNAME}" bold green - } + printf ' ' - printf ' ' + __fontify '\w' bold blue - __fontify "$(__ps1-pwd)" bold blue + test "${PS1_SHOWGITSTATUS}" && { + printf ' ' + __fontify "$(__git_ps1 '(%s)')" red + } - test "${PS1_SHOWGITSTATUS}" && { - printf ' ' - __fontify "$(__git_ps1 '(%s)')" red - } + printf '\\n' - echo + __fontify '\$' dim + printf ' ' + ) } __smart-term/refresh () @@ -161,8 +169,8 @@ __smart-term/refresh () __set-title __signal-no-newline - __signal-rc ${rc} - __write-context + __write-epilogue ${rc} + __smart-term/set-ps1 } __smart-term/init () @@ -179,10 +187,6 @@ __smart-term/init () PROMPT_COMMAND=__smart-term/refresh - PS1=$( - BUILDING_PS=t - __fontify '\$ ' dim - ) PS2=$( BUILDING_PS=t __fontify '… ' dim @@ -199,7 +203,7 @@ __smart-term/init () __dumb-term/refresh () { local -ir rc=$? - __signal-rc ${rc} + __write-epilogue ${rc} } __dumb-term/init () @@ -212,13 +216,12 @@ __dumb-term/init () # # ^[[?2004l^M^J^[[?2004h # - # … whenever I send a command, which 'M-x shell' fails to - # completely scrub, leaving a spurious empty line. Possibly - # comint.el could learn to clean those sequences better; until - # then, this will do: + # … whenever I send a command in a nested shell ('bash' started + # within the original shell, without --noediting). + # + # Until I figure something smarter: bind 'set enable-bracketed-paste off' 2>/dev/null - # (Silence stderr, since Bash will sometimes complain about "line - # editing not enabled", despite the bind command working fine). + # (Silence stderr: 'bind' complains when run with --noediting) }