Skip to content

Instantly share code, notes, and snippets.

@numpde
Created June 10, 2023 07:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save numpde/5528b8a4cd9e4b55f3afbee28bcf96b7 to your computer and use it in GitHub Desktop.
Save numpde/5528b8a4cd9e4b55f3afbee28bcf96b7 to your computer and use it in GitHub Desktop.
Set title for the terminal immediately
set-title() {
if [[ -z "$PS1_BAK" ]]; then
PS1_BAK=$PS1
fi
# Change the title immediately using printf
printf "\033]0;%s\007" "$1"
# Update PS1 for future prompts
TITLE="\[\e]2;$1\a\]"
PS1=${PS1_BAK}${TITLE}
}
# Usage:
# set-title "New terminal title" && sleep 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment