13

I set meaningful names to new windows I create in gnu screen, but then when I 'cd' or open vim that name gets changed to 'pwd' for instance. Is there a way to prevent screen from changing the title? I know there's a setting like that in tmux, but for some reason vim scrolls really slow in tmux with multiple vertical splits, so I had to abandon it (tmux). Ideas appreciated!

4

gnu screen does not appear to have a way to turn the feature off (and you would be applying this selectively in any case). The way to fix it would be to modify the shell- and vim-behavior:

| improve this answer | |
3

In Centos this is fixed by creating /etc/sysconfig/bash-prompt-screen which is executed by the default /etc/bashrc. If you

touch /etc/sysconfig/bash-prompt-screen
chmod +x /etc/sysconfig/bash-prompt-screen
exec bash

then it will execute, which does nothing (since its empty), and leave your window titles alone from thereon. (Note the exec bash to restart bash to trigger this in your current shell.)

hardstatus alwaysignore did not work for me

| improve this answer | |
  • 1
    with 4.06.02 (the version I'm running) alwaysignore will make screen eat the esc sequences even if your prompt-command/whatever is sending them. – Ricky Beam Mar 27 '19 at 4:21
2

The line in /etc/screenrc that was the problem for me was

hardstatus string "[screen %n%?: %t%?] %h"

Once that was identified, I did not have to edit the system file. I could work around screen changing the title with

CTRL-A:hardstatus alwaysignore

for the current window, or by adding the following to my ~/.screenrc for future windows:

hardstatus alwaysignore

(I set my terminal window's tab and window titles from my bash prompt to include useful information and screen was not helping me.)

| improve this answer | |
  • alwaysignore is the path to sanity. – Ricky Beam Mar 27 '19 at 4:14
  • again, this doesn't work (on debian I havent found a solution, there's no /etc/sysconfig/bash-prompt-screen). Hitting enter at the prompt on a Centos box i'm ssh'd into resets the window title on me immediately. I can do a unset PROMPT_COMMAND on the system in question, but I'd have to do that on every system preemptively I share logins (as root... sigh) with others. There must be a way to have screen protect itself from modifications from client windows (if not I sense a security problem). – math Apr 16 '19 at 18:28
1

What "windows" are you talking about?

Screen and maybe the shell and vim send term-escape codes to the terminal for these things. Some terminal emulators are not so good at catching them all and will essentially go fubar. But it's been ages since I've seen that happen.

With screen, you can set the title of the window with title <title> and set it up programatically (by binding to keys or special ESC sequences) however you want. Ultimately, these programs emit a sequence to your terminal. You can use the PROMPT_COMMAND environment variable to dynamically change this depending on, for instance, your cwd. Here's mine, which apparently is set by my system's /etc/bashrc

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

To make the title completely go away, you must do (at least) three things:

  1. close all but 1 screen and unset PROMPT_COMMAND at the command prompt and in your ~/.profile after /etc/bashrc is loaded.
  2. Use screen's title command. Hit Ctrl-A then : then title ""<CR>. You can set this in .screenrc as well.
  3. Send a null sequence from the shell:

    printf "\033]0;\033\\"
    

If something else (like vim) is setting it, we'll need to do further research.

In the screen man page, there's a section on TITLES in which they discuss this at length.

| improve this answer | |
1

Related, I found that after setting my window title (and ensuring that PROMPT_COMMAND was unset and that nothing untoward was in my PS1), that launching screen on some systems would result in my window title changing. After lots of experiments and frustration I finally found that by grabbing the screen package's installed file /etc/screenrc from a system that did NOT have this problem and using that to replace the same file on a system that did have the problem, it fixed my issue. screen now no longer changes my window title. Now exactly, what line or lines in the /etc/screenrc are doing that I do not know. The diff between the two screenrc's is huge and so I didn't even bother trying to sleuth it out.

| improve this answer | |
0

Solution for GNU Screen 4.5.0 and newer

GNU Screen 4.5.0 and newer does have an option to stop terminal content from changing window titles, see this bug ticket (via, formatting mine):

Since v.4.5.0 there is

defdynamictitle [on|off]

for global setting and

dynamictitle  [on|off]

for per window settings.

Partial Solution for older GNU Screen versions

As I had to use an older version of Screen and as I was mostly annoyed by changes through bash (even after only hitting Enter), I resorted to unsetting the PROMPT_COMMAND variable (via) in my ~/.bashrc file:

unset PROMPT_COMMAND
| improve this answer | |

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.