See also
You can customize each window's name in the window display (viewed with the “windows
” command (C-a w
)) by setting it with one of the title commands. Normally the name displayed is the actual command name of the program created in the window. However, it is sometimes useful to distinguish various programs of the same name or to change the name on-the-fly to reflect the current state of the window.
The default name for all shell windows can be set with the “shelltitle
” command in the .screenrc file, while all other windows are created with a “screen
” command and thus can have their name set with the -t
option. Interactively, there is the title-string escape-sequence (<esc>kname<esc>
) and the “title
” command (C-a A
). The former can be output from an application to control the window's name under software control, and the latter will prompt for a name when typed. You can also bind pre-defined names to keys with the “title
” command to set things quickly without prompting.
Finally, screen
has a shell-specific heuristic that is enabled by setting the window's name to “search|name” and arranging to have a null title escape-sequence output as a part of your prompt. The search portion specifies an end-of-prompt search string, while the name portion specifies the default shell name for the window. If the name ends in a ':
' screen
will add what it believes to be the current command running in the window to the end of the window's shell name (e.g. “name:cmd”). Otherwise the current command name supersedes the shell name while it is running.
Here's how it works: you must modify your shell prompt to output a null title-escape-sequence (<esc>k<esc>
) as a part of your prompt. The last part of your prompt must be the same as the string you specified for the search portion of the title. Once this is set up, screen
will use the title-escape-sequence to clear the previous command name and get ready for the next command. Then, when a newline is received from the shell, a search is made for the end of the prompt. If found, it will grab the first word after the matched string and use it as the command name. If the command name begins with either '!
', '%
', or '^
' screen
will use the first word on the following line (if found) in preference to the just-found name. This helps csh users get better command names when using job control or history recall commands.
Here's some .screenrc examples:
screen -t top 2 nice top
Adding this line to your .screenrc would start a nice-d version of the “top
” command in window 2 named “top” rather than “nice”.
shelltitle '> |csh' screen 1
These commands would start a shell with the given shelltitle. The title specified is an auto-title that would expect the prompt and the typed command to look something like the following:
/usr/joe/src/dir> trn
(it looks after the '> ' for the command name). The window status would show the name “trn” while the command was running, and revert to “csh” upon completion.
bind R screen -t '% |root:' su
Having this command in your .screenrc would bind the key sequence “C-a R
” to the “su
” command and give it an auto-title name of “root:”. For this auto-title to work, the screen could look something like this:
% !em emacs file.c
Here the user typed the csh history command “!em
” which ran the previously entered “emacs
” command. The window status would show “root:emacs” during the execution of the command, and revert to simply “root:” at its completion.
bind o title bind E title "" bind u title (unknown)
The first binding doesn't have any arguments, so it would prompt you for a title when you type “C-a o
”. The second binding would clear an auto-title's current setting (C-a E
). The third binding would set the current window's title to “(unknown)” (C-a u
).
One thing to keep in mind when adding a null title-escape-sequence to your prompt is that some shells (like the csh) count all the non-control characters as part of the prompt's length. If these invisible characters aren't a multiple of 8 then backspacing over a tab will result in an incorrect display. One way to get around this is to use a prompt like this:
set prompt='^[[0000m^[k^[\% '
The escape-sequence “<esc>[0000m
” not only normalizes the character attributes, but all the zeros round the length of the invisible characters up to 8. Bash users will probably want to echo the escape sequence in the PROMPT_COMMAND:
PROMPT_COMMAND='echo -n -e "\033k\033\134"'
(I used “\134
” to output a '\
' because of a bug in bash v1.04).