Universal shell script that adds a title command for setting terminal window titles in both Zsh and Bash.
title "Your Title"sets a custom terminal title.- Re-applies your custom title before each prompt so other prompt hooks do not overwrite it.
- Works in both Zsh and Bash.
- Copy
termtitle.shto a location such as~/bin/termtitle.sh. - Source it from your shell config:
source ~/bin/termtitle.shsource ~/bin/termtitle.sh- Reload your shell:
source ~/.zshrc
# or
source ~/.bashrctitle "My Session"- In Bash, the script appends a refresher to
PROMPT_COMMANDand removes default PS1 title escape sequences. - In Zsh, the script installs a
precmdhook.