Created
February 5, 2026 07:35
-
-
Save ozbek/3c2db874d3b68965ee6e127e4edfd791 to your computer and use it in GitHub Desktop.
GNOME Terminal: custom title
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() { | |
| # Lazy-capture original PS1 on first use | |
| if [[ -z "${_SET_TITLE_ORIG_PS1+x}" ]]; then | |
| _SET_TITLE_ORIG_PS1="$PS1" | |
| fi | |
| if [[ "$1" == "--clear" ]]; then | |
| PS1="$_SET_TITLE_ORIG_PS1" | |
| elif [[ -z "$1" || "$1" == --* ]]; then | |
| echo "Usage: set-title \"Your Custom Title\"" | |
| echo " set-title --clear" | |
| return 1 | |
| else | |
| # Strip existing title sequence (\[\e]0;...\a\]) from the original PS1, | |
| # otherwise it would run after ours and overwrite the custom title. | |
| local base_ps1="${_SET_TITLE_ORIG_PS1#*\\a\\]}" | |
| PS1="\[\e]0;$1\a\]${base_ps1}" | |
| fi | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment