Created
December 11, 2020 02:39
-
-
Save sanmai/9390659f10524bc9a037e60f212eeacf to your computer and use it in GitHub Desktop.
This file contains 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
# 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