16

I like to pop up a screen session with pre-opened SSH connections to the primary servers that I administrate at the office. I give these windows each a very brief name, typically 2-4 characters, so they appear in my screen status bar with those names. So I'll have a screen entry that looks like

0$ jen1 ... 

Now, when I need to switch to that server and do anything even as simple as fetch a directory listing, that name suddenly expands and becomes

0$ ghellings@devjenkins01 

The same happens for each and every window as I access it, making my status bar quickly overflow the horizontal width of my screen. I would like to lock the name in place at window creation time and prevent client applications from changing it. I don't want any applications to be able to change the screen window title (quite the opposite of what lots of people seem to be asking). This becomes especially cumbersome once I change to that screen and open a directory somewhere. Then the screen title becomes

 (0*$ ghellings@devjenkins01:/opt/somepackage/software/subdirectory) 

I want it to only change the active status so it will always read either

`0$ jen1` or `(0*$ jen1)` 

Is there a way for me to lock the window name in and prevent changing it?

3 Answers 3

11

I found this early on in RHEL 7 testing and it would drive me nuts. What I discovered is that there was a change to /etc/bashrc in RHEL 7 that causes the naming of windows in screen and tmux to change whenever a command like cd or ls is run. In section screen*)

if [ -e /etc/sysconfig/bash-prompt-screen ]; then PROMPT_COMMAND=/etc/sysconfig/bash-prompt-screen else ## RHEL 7 PROMPT_COMMAND='printf "\033k%s@%s:%s\033\\" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/~}"' ## RHEL 6 PROMPT_COMMAND='printf "\033]0;%s@%s:%s\033\\" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/~}"' fi 

So in RHEL 7 the change was from ]0; to k in the PROMPT_COMMAND section.

I had considered opening a bug, but just never got around to it. I usually just change it manually on a fresh install.

  • Changes made to update formatting
0
8

Most probably, you have the PROMPT_COMMAND variable set to something like

printf "\033k%s@%s:%s\033\\" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/~}" 

I have exactly this on a CentOS 7 system. This sets the xterm window title after each command, which screen uses as window title.

Just unset PROMPT_COMMAND in your .bashrc or edit /etc/bashrc to not set it.

1
  • See below to make this more permanent. Commented Nov 16, 2018 at 18:53
3

If you check .bashrc or /etc/bashrc, you may see if or case which is related to screen.

In my case, it was something like:

if [ -e /etc/sysconfig/bash-prompt-screen ]; then PROMPT_COMMAND=/etc/sysconfig/bash-prompt-screen else PROMPT_COMMAND='printf "\033k%s@%s:%s\033\\" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/~}"' fi 

under case $TERM in in /etc/bashrc file.

The problem was that I did not have the file /etc/sysconfig/bash-prompt-screen so PROMPT_COMMAND under else is used.

I just made an empty /etc/sysconfig/bash-prompt-screen file then titles of screen windows are not dynamically changed anymore!

1
  • Have to make the empty file executable or you'll get a warning every time bash is launched (eg at login for everyone). Commented Nov 16, 2018 at 18:54

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.