Skip to content

Instantly share code, notes, and snippets.

@chris-piekarski
Created October 26, 2025 19:47
Show Gist options
  • Select an option

  • Save chris-piekarski/e1061c9a7e0d095683da8a99fa274530 to your computer and use it in GitHub Desktop.

Select an option

Save chris-piekarski/e1061c9a7e0d095683da8a99fa274530 to your computer and use it in GitHub Desktop.
PROMPT_COMMAND
export PROMPT_COMMAND='
# Get relative path (~ instead of /home/user)
relpath=$PWD
case "$relpath" in
$HOME*) relpath="~${relpath#$HOME}";;
esac
[ ${#relpath} -gt 30 ] && relpath="…${relpath: -30}"
# Get current git branch if inside a repo
branch=$(git rev-parse --abbrev-ref HEAD 2>/dev/null)
# Get timestamp (HH:MM:SS)
timestamp=$(date +"%H:%M:%S")
# Choose separator based on branch presence
sep=":"
[ -n "$branch" ] && sep="·"
# Build and print tab title
printf "\033]0;%s%s%s%s [%s]\007" \
"$(hostname)" "$sep" "$relpath" \
"${branch:+ ($branch)}" "$timestamp"
'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment