Compare commits
4 Commits
a2b0771c28
...
33c485caa5
| Author | SHA1 | Date |
|---|---|---|
|
|
33c485caa5 | |
|
|
82fd24681f | |
|
|
05afd18b1a | |
|
|
f730f0f604 |
43
bashrc
43
bashrc
|
|
@ -125,11 +125,50 @@ 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 PS1 with time, user@host, directory on first line, git status on second line, prompt on third line
|
# Set up prompt command to draw divider, update git status, and calculate 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\]'
|
PROMPT_COMMAND="draw_prompt_divider; my_gitstatus_prompt_update; calculate_git_alignment"
|
||||||
|
|
||||||
|
# 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,5 +60,4 @@ 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