Compare commits
No commits in common. "33c485caa5ae3329f5bcb80803d1acf0b7889553" and "a2b0771c286a8bf8119e9a700c4ac732da63fc2d" have entirely different histories.
33c485caa5
...
a2b0771c28
43
bashrc
43
bashrc
|
|
@ -125,50 +125,11 @@ function show_date() {
|
||||||
|
|
||||||
export HISTCONTROL=ignoreboth:erasedups
|
export HISTCONTROL=ignoreboth:erasedups
|
||||||
|
|
||||||
# Optimized divider function - reduced subshells and calculations
|
|
||||||
function draw_prompt_divider() {
|
|
||||||
local timestamp prefix_length line_length i
|
|
||||||
printf -v timestamp '%(%H:%M:%S)T' -1 # Faster than $(date)
|
|
||||||
local prefix="$timestamp ├"
|
|
||||||
prefix_length=${#prefix}
|
|
||||||
line_length=$(( ${COLUMNS:-80} - prefix_length ))
|
|
||||||
|
|
||||||
# Print prefix then fill with box-drawing characters
|
|
||||||
printf '%s' "$prefix"
|
|
||||||
for ((i=0; i<line_length; i++)); do printf '─'; done
|
|
||||||
echo
|
|
||||||
}
|
|
||||||
|
|
||||||
# Cache static values that don't change during session
|
|
||||||
_CACHED_USER_HOST="$USER@$HOSTNAME"
|
|
||||||
_CACHED_USER_HOST_LENGTH=${#_CACHED_USER_HOST}
|
|
||||||
|
|
||||||
# Optimized git alignment calculation
|
|
||||||
function calculate_git_alignment() {
|
|
||||||
# Only calculate if git status exists
|
|
||||||
[[ -z "$GITSTATUS_PROMPT" ]] && { GIT_ALIGNMENT_PADDING=""; return; }
|
|
||||||
|
|
||||||
# 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}))
|
|
||||||
[[ $needed_padding -lt 8 ]] && needed_padding=8
|
|
||||||
|
|
||||||
# Use printf once to generate padding
|
|
||||||
printf -v GIT_ALIGNMENT_PADDING '%*s' $needed_padding ''
|
|
||||||
}
|
|
||||||
|
|
||||||
# Load custom gitstatus configuration
|
# Load custom gitstatus configuration
|
||||||
[ -f "$HOME/.config/bash/gitstatus-custom.sh" ] && . "$HOME/.config/bash/gitstatus-custom.sh"
|
[ -f "$HOME/.config/bash/gitstatus-custom.sh" ] && . "$HOME/.config/bash/gitstatus-custom.sh"
|
||||||
|
|
||||||
# Set up prompt command to draw divider, update git status, and calculate alignment
|
# Set PS1 with time, user@host, directory on first line, git status on second line, prompt on third line
|
||||||
PROMPT_COMMAND="draw_prompt_divider; my_gitstatus_prompt_update; calculate_git_alignment"
|
PS1='\t \[\033[01;32m\]\u@\h\[\033[00m\] \[\033[1;34m\]\w\[\033[00m\]\n${GITSTATUS_PROMPT:+ $GITSTATUS_PROMPT\n}\[\033[01;$((31+!$?))m\]\$\[\033[00m\] \[\e]0;\u@\h: \w\a\]'
|
||||||
|
|
||||||
# Set PS1 with user@host, directory on first line, dynamically aligned git status, prompt on third line
|
|
||||||
PS1='\[\033[01;32m\]\u@\h\[\033[00m\] \[\033[1;34m\]\w\[\033[00m\]\n${GITSTATUS_PROMPT:+$GIT_ALIGNMENT_PADDING$GITSTATUS_PROMPT\n}\[\033[01;$((31+!$?))m\]\$\[\033[00m\] \[\e]0;\u@\h: \w\a\]'
|
|
||||||
|
|
||||||
# If there are multiple matches for completion, Tab should cycle through them
|
# If there are multiple matches for completion, Tab should cycle through them
|
||||||
bind TAB:menu-complete
|
bind TAB:menu-complete
|
||||||
|
|
|
||||||
|
|
@ -60,4 +60,5 @@ function my_gitstatus_prompt_update() {
|
||||||
|
|
||||||
# Start gitstatusd and set up prompt command
|
# Start gitstatusd and set up prompt command
|
||||||
gitstatus_stop && gitstatus_start -s -1 -u -1 -c -1 -d -1
|
gitstatus_stop && gitstatus_start -s -1 -u -1 -c -1 -d -1
|
||||||
|
PROMPT_COMMAND=my_gitstatus_prompt_update
|
||||||
shopt -s promptvars
|
shopt -s promptvars
|
||||||
Loading…
Reference in New Issue