From 82fd24681f282f4f56100ad083dc8d2c49989496 Mon Sep 17 00:00:00 2001 From: ray Date: Tue, 30 Sep 2025 21:03:56 +0100 Subject: [PATCH] optimize prompt divider and git alignment calculations Refactor the draw_prompt_divider function for improved performance by reducing subshells and using faster timestamp retrieval. Update the calculate_git_alignment function to cache static values and simplify branch name extraction for better efficiency. --- bashrc | 58 +++++++++++++++++++++++----------------------------------- 1 file changed, 23 insertions(+), 35 deletions(-) diff --git a/bashrc b/bashrc index 5b9684b..c9fa5f8 100644 --- a/bashrc +++ b/bashrc @@ -125,52 +125,40 @@ function show_date() { export HISTCONTROL=ignoreboth:erasedups -# Function to draw a terminal-width divider line with timestamp +# Optimized divider function - reduced subshells and calculations function draw_prompt_divider() { - local width=${COLUMNS:-80} # Use terminal width, fallback to 80 - local timestamp=$(date '+%H:%M:%S') + local timestamp prefix_length line_length i + printf -v timestamp '%(%H:%M:%S)T' -1 # Faster than $(date) local prefix="$timestamp ā”œ" - local prefix_length=${#prefix} - local line_length=$((width - prefix_length)) + prefix_length=${#prefix} + line_length=$(( ${COLUMNS:-80} - prefix_length )) - # Print timestamp + junction + line to fill remaining width + # Print prefix then fill with box-drawing characters printf '%s' "$prefix" - printf '%.0s─' $(seq 1 $line_length) + for ((i=0; i