add prompt divider and update command for gitstatus

Introduced a function to draw a terminal-width divider with a timestamp
and updated the PROMPT_COMMAND to include this new function for better
visual separation in the terminal prompt.
This commit is contained in:
Ray Elliott 2025-09-30 20:44:24 +01:00
parent a2b0771c28
commit f730f0f604
2 changed files with 17 additions and 3 deletions

18
bashrc
View File

@ -125,11 +125,25 @@ function show_date() {
export HISTCONTROL=ignoreboth:erasedups
# Function to draw a terminal-width divider line with timestamp
function draw_prompt_divider() {
local width=${COLUMNS:-80} # Use terminal width, fallback to 80
local timestamp=$(date '+%H:%M:%S')
local prefix="$timestamp"
local prefix_length=${#prefix}
local line_length=$((width - prefix_length))
# Print timestamp + junction + line to fill remaining width
printf '%s' "$prefix"
printf '%.0s─' $(seq 1 $line_length)
echo
}
# Load custom gitstatus configuration
[ -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
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, git status on second line, prompt on third line
PS1='\[\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\]'
# If there are multiple matches for completion, Tab should cycle through them
bind TAB:menu-complete

View File

@ -60,5 +60,5 @@ function my_gitstatus_prompt_update() {
# Start gitstatusd and set up prompt command
gitstatus_stop && gitstatus_start -s -1 -u -1 -c -1 -d -1
PROMPT_COMMAND=my_gitstatus_prompt_update
PROMPT_COMMAND="draw_prompt_divider; my_gitstatus_prompt_update"
shopt -s promptvars