Skip to content

Set Shell Title in WSL/Ubuntu without destroying PS1 #122

@Dakkaron

Description

@Dakkaron

Currently the documentation recommends setting the shell title this way:

PS1=$
PROMPT_COMMAND=
echo -ne "\033]0;New Title\a"

This sucks, because it sets PS1 to $. It would be much better to do this:

export PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
echo -ne '\033]0;New Title\a'

This way, the command prompt stays the way it is, but setting the title still works.

Even better, add this to the end of ~/.bashrc:

settitle () {
  export PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
  echo -ne '\033]0;'"$1"'\a'
}

What this does is it adds the command settitle that can be used at any time to change the window title like so:

settitle 'New Title'

Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions