Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'd like to have my current $PS1 prompt (\u@\h:\w$(__git_ps1 "(%s)")\$ plus some coloring) to be also used as screen's window title (in the hardline) and as the xterm window title. How can this be achieved?

share|improve this question

An incomplete solution would be to modify your $PS1 prompt once inside a GNU screen. Start by modifying your shell's RC file (ie ~/.bashrc). Look for a case statement that evaluates $TERM:

case "$TERM" in
    PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"

Add the following prior to the catch all (ie *)):

    PS1='\e]0;\u@\h:\w\a\ek\u@\h:\w\e\\\u@\h:\w$(__git_ps1 "(%s)")\$ '

This will modify your hardstatus: \e]0;...\a

This will modify your window title: \ek...\e\\

The hardstatus will not show up unless you have configured it to do so. For example, you could add the following to your .screenrc:

hardstatus alwayslastline

Complex hardstatus string options will continue to work. You can substitute your now dynamic stored hardstatus for the current window using %h:

hardstatus string '%{= kw}[ %h ] %=%{w}[ %{r}%l%{w} ]%{w}[%{y} %Y-%m-%d %C %A %{w}]%{w}'

This will set the hardstatus line to the stored hardstatus between two brackets on the left side of the screen and the CPU utilization to the right along with the date and time.


 [ username@host:~ ]                    [ 0.00 0.01 0.00 ][ 2012-11-27  4:13 PM ]


  1. This will most likely break your cursor offset in your shell's history recall. (Hit your up arrow a few times, then try to edit that line. You'll see what I mean.) This is because most shells use the length for $PS1, and this will include the non-printable characters added to $PS1.

  2. This will most likely break the xterm title bar, "freezing" it to the last status set prior to running GNU screen. What is interesting is that applications like vim that update the title bar will continue to work.

  3. Manually setting the screen title (ie C-A A) will still work until the command prompt is updated.

share|improve this answer

with bash, to change screen title dynamically to $YourVariable ( screenrc caption variable %t) export PROMPT_COMMAND="echo -ne '\033k$YourVariable\033\\'"

Possibility is to use also hardstatus ( screenrc caption variable %h) if not inside "screen", will change window (terminal emulator) title
export PROMPT_COMMAND="echo -ne '\033]0;$YourVariable\007'"

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.