Skip to content

Instantly share code, notes, and snippets.

@sanmai
Created December 11, 2020 02:39
Show Gist options
  • Save sanmai/9390659f10524bc9a037e60f212eeacf to your computer and use it in GitHub Desktop.
Save sanmai/9390659f10524bc9a037e60f212eeacf to your computer and use it in GitHub Desktop.
# add to .profile
set-title () {
# If the length of string stored in variable `PS1_BAK` is zero...
# - See `man test` to know that `-z` means "the length of STRING is zero"
if [[ -z "$PS1_BAK" ]]; then
# Back up your current Bash Prompt String 1 (`PS1`) into a global backup variable `PS1_BAK`
PS1_BAK="$PS1"
fi
# Set the title escape sequence string with this format: `\[\e]2;new title\a\]`
# - See: https://wiki.archlinux.org/index.php/Bash/Prompt_customization#Customizing_the_terminal_window_title
TITLE="\[\e]2;$@\a\]"
# Now append the escaped title string to the end of your original `PS1` string (`PS1_BAK`), and set your
# new `PS1` string to this new value
PS1="${PS1_BAK}${TITLE}"
}
set-title '$(basename "$PWD")'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment