From b394159a6ee494978fc91ee049c1c9568228c6fa Mon Sep 17 00:00:00 2001 From: Leo Date: Thu, 29 Jan 2026 17:56:41 +0200 Subject: [PATCH] Fix issue with bash prompt length detection --- .bash_prompt | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/.bash_prompt b/.bash_prompt index ca7c75d..32087bb 100644 --- a/.bash_prompt +++ b/.bash_prompt @@ -3,22 +3,28 @@ case "$TERM" in xterm-color|*-256color) color_prompt=yes;; esac -function parse_git_branch() { - # git branch --show-current 2>/dev/null | sed 's/^/ (/' | sed 's/$/)/' - +function __set_prompt() { local branch branch=$(git branch --show-current 2>/dev/null) - #[[ -n "$branch" ]] && printf ' \033[44;30m %s \033[0;34m\ue0b0\033[0m' "$branch" + + # Colors (wrapped in \[ \] for proper length calculation) + local yellow_bg='\[\033[43;30m\]' + local blue_bg='\[\033[44;30m\]' + local yellow_on_blue='\[\033[44;33m\]' + local blue='\[\033[0;34m\]' + local yellow='\[\033[0;33m\]' + local reset='\[\033[0m\]' + local arrow=$'\ue0b0' if [[ -n "$branch" ]]; then - printf '\033[44;33m'$'\ue0b0''\033[44;30m %s \033[0;34m'$'\ue0b0''\033[0m' "$branch" + PS1="${yellow_bg} \w ${yellow_on_blue}${arrow}${blue_bg} ${branch} ${blue}${arrow}${reset} " else - printf '\033[0;33m'$'\ue0b0''\033[0m' + PS1="${yellow_bg} \w ${yellow}${arrow}${reset} " fi - } +} if [ "$color_prompt" = yes ]; then - PS1='\[\033[43;30m\] \w \[$(parse_git_branch)\] ' + PROMPT_COMMAND=__set_prompt else PS1='\w\$ ' fi