From 9b73f4cc9b3a9ae981797697f523260f0d11574f Mon Sep 17 00:00:00 2001 From: Quinn Date: Wed, 19 Nov 2025 12:59:26 +0100 Subject: [PATCH] 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. --- .bashrc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.bashrc b/.bashrc index ff76596..e009a9e 100644 --- a/.bashrc +++ b/.bashrc @@ -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