From 33c485caa5ae3329f5bcb80803d1acf0b7889553 Mon Sep 17 00:00:00 2001 From: ray Date: Tue, 30 Sep 2025 21:07:50 +0100 Subject: [PATCH] improve branch name extraction in git alignment Use sed for reliable escape sequence removal in the calculate_git_alignment function to enhance performance. --- bashrc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bashrc b/bashrc index c9fa5f8..2258a00 100644 --- a/bashrc +++ b/bashrc @@ -148,10 +148,10 @@ function calculate_git_alignment() { # Only calculate if git status exists [[ -z "$GITSTATUS_PROMPT" ]] && { GIT_ALIGNMENT_PADDING=""; return; } - # Fast branch name extraction using bash parameter expansion - local cleaned="${GITSTATUS_PROMPT//[$'\001\002']/}" # Remove \001 \002 - cleaned="${cleaned//$'\e['[0-9\;]*m/}" # Remove ANSI codes - local branch_name="${cleaned%% *}" # Get first word (branch) + # Fast branch name extraction - use sed for reliable escape sequence removal + local cleaned + cleaned=$(echo "$GITSTATUS_PROMPT" | sed -e 's/\x01//g' -e 's/\x02//g' -e 's/\x1b\[[0-9;]*m//g') + local branch_name="${cleaned%% *}" # Get first word (branch) # Calculate padding (cache the static hostname length) local needed_padding=$((_CACHED_USER_HOST_LENGTH - ${#branch_name}))