0

I wanted to add information about Git branch to my command line prompt, and I found this post:

parse_git_branch() {
     git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}

export PS1="\u@\h \[\033[32m\]\w\[\033[33m\]\$(parse_git_branch)\[\033[00m\] $ "

I added those lines into my .bashrc.

It works, shows the Git branch in the prompt (joedoe@machine1 ~/git/repo1 (dev_branch) $ ), however, it messes up my GNOME Terminal's window title, which used to contain current working directory, and now it just says "Terminal."

Why did this change the terminal window title? Is there a better solution?

2
  • What was the previous value of $PS1 before your change?
    – choroba
    Jun 29, 2021 at 10:16
  • It was \[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$
    – Danijel
    Jun 29, 2021 at 10:17

1 Answer 1

1

This part of the old $PS1 sets the title:

\[\e]0;\u@\h: \w\a\]

The \[...\] part just means the characters inside don't change the length of the prompt. \e]0;...\a is used to set the title, the title was set to \u@\h: \w which translates to username@hostname: workdir.

Include the pattern into your new PS1 to get the same behaviour.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .