fix: bash prompt weirdness

Under certain situations, the bash prompt was not getting aligned
properly.
Mainly when writing a bunch of text, and removing it with M-BS, where
the width of the printed text is kept.
This commit is contained in:
2025-11-19 12:59:26 +01:00
parent 8a2fbc92ff
commit 9b73f4cc9b

View File

@@ -50,11 +50,13 @@ __regenprompt() {
local err=$? # acquire the error code of the last executed command
local git=$(__lazy_git_ps1)
# Format the error code to be in the last column of the terminal
# this shall be printed as non-printable characters, so won't effect text wrapping.
if [ $err -ne 0 ]; then
err="\[\033[$((COLUMNS - 4))G\033[01;31m\]${err}\[\033[0G\]"
err="\033[$((COLUMNS - 4))G\033[01;31m${err}\033[0G"
else unset err; fi
PS1="$err" # error code
PS1="\[$err\]" # error code
PS1="$PS1\[\033[?25h\]" # show cursor
PS1="$PS1\[\033[01;35m\]\u@\h" # user@host
PS1="$PS1\[\033[00m\]:" # separator