gnu screen not to change my window titles

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!


Solution 1:

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:

  • the bash shell typically does this in the PROMPT_COMMAND special variable. The XTerm Title How-To has general information on that topic. The Set the title of the terminal window to the current directory question also has useful information.
  • vim does this using the title mode/setting. If you had set notitle in your .vimrc that should be enough.

Solution 2:

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

Solution 3:

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.