I'm trying to improve the aspect of GNU Screen using the screenrc file, I tuned colors, status line, caption and the list of the loaded windows.

The only thing I'm not able to achieve is getting the caption with the current executed command as in the below picture, note the vim caption in the right pane:

enter image description here

What I currently have is this, and what I would like to obtain is having captions (and if possible also hardstatus line) with |0 less| 1 man instead of the current |0 bash| 1 bash.

How can I do this?

Update: Until now the only working solution I found is in this post but it doesn't print what I need...

However that is the only working dynamic title I found until now.

PROMPT_COMMAND='echo -ne "\033k\033\134\033k${HOSTNAME}[`basename ${PWD}`]\033\134"'`

in .bashrc and shelltitle '] |bash' in .screenrc. The title is updated with the hostname and the basename of the working directory, but the prompt is completely wrong (it also has a leading space):

  • checkout the updates on the answer – Torian Feb 12 '11 at 2:03

In your .bashrc file set your PROMPT_COMMAND like this:


case "$TERM" in
    screen*) PROMPT_COMMAND='echo -ne "\033k\033\0134"'

UPDATE: seems to be a bug with echo built into bash. Solution should be either use of /bin/echo or \0134. Try:

$ echo -e "\134 = \0134"
\134 = \
$ /bin/echo -e "\134 = \0134"
\ = \

This is the escape sequence that screen needs to identify which command is being run, and replace the title of your current window.

Then, on your .screenrc file, make sure the following lines exist:

shelltitle '> |something:'
hardstatus alwayslastline

The pattern search|name tells screen to search your end-of-prompt for some string (in this case, '> '). The name part, specifies the default shell name for the window. So, when you have nothing but the shell running, you'll see something like:

$ something:

But when you run top:

$ something:top
  • Almost... Your hint for \0134 or /bin/echo works with my above example, so I can have the caption updated with the string between two escape sequences without having my prompt messed. But I can't still make your example working. My prompt under screen is ${debian_chroot:+($debian_chroot)}\u@\h:\w\$ so I'm using shelltitle '$ |bash', is that right? – Fabio Feb 12 '11 at 14:07
  • thanks, I'm having it work without the hardstatus ... line in .screenrc, I'm using caption always ..., not a screen guru though. – ryenus Jul 4 '14 at 1:41
  • Note that the shelltitle stuff has to actually be in your .screenrc - nothing will happen if you enter it at the screen command prompt, for some reason. – Greg Bell Oct 1 '17 at 10:28
  • The /bin/echo option isn't portable, the echo binary differs between linux and other unices like BSD and macOS. Using the printf built-in is likely the better solution. – ghoti Nov 5 '19 at 3:26

As an alternative, you could use tmux instead of screen. Tmux will automatically set the current window's title.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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