Created
June 10, 2023 07:49
-
-
Save numpde/5528b8a4cd9e4b55f3afbee28bcf96b7 to your computer and use it in GitHub Desktop.
Set title for the terminal immediately
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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