Warning: Undefined array key "stylesheets" in /home/public/screen/inc/StyleUtils.php on line 102

Site Tools


Title Examples

Each screen window has a title. The title is visible in the window display (from the windows command or C-a w) and you can use titles as well as numbers to specify windows for many screen commands.

You can set the default title for your windows with the shelltitle command in your .screenrc. That may be overridden by the -t option of the screen command, the title-string escape sequence (<esc>k<new-title><esc>\), and the title command (bound to C-a A).

Simple examples

In .screenrc, set the default title of all windows to “cardamom”:

shelltitle "cardamom"

In .screenrc, from screen's command line, or from a shell inside screen, make a new window with the title “anise”:

screen -t anise

The escape sequence can be used from any program to set the title. Here are examples for the command line:

echo -ne '\ekcommand-line\e\\'

a bash shell prompt:

export PS1='\[\033kbash\033\\\]$ '

and, just for fun, Emacs Lisp:

(send-string-to-terminal "\ekemacs\e\\")

Setting the title to the host you ssh'd into

Setting the title to the name of the running program

A common desire is to name one's windows after the programs running in them. A window sitting at a shell prompt might be named “bash”, while one running pine from a shell would be named “pine”.

If you're running tcsh or zsh, you have the easiest time of this. Both of those shells define a special symbol that is run after a command is entered. In tcsh, it's the alias postcmd. Here's a simple example:

alias postcmd 'echo -ne "^[k\!#:0^[\\"'

On non-Linux systems like (Free)BSD or Solaris you may use the POSIX version with printf:

alias postcmd 'printf "\033k\!#\033\\"'

In zsh, it's the shell function preexec:

preexec () {
  echo -ne "\ek${1%% *}\e\\"
}

Other shells have no such feature, but screen has heuristics to fake it. You have to tell screen what the end of your prompt looks like, and let it know when you're sitting at a prompt. For the first part, give screen a shelltitle of the form “<prompt-end>|<default-title>” where <prompt-end> is a string that will always appear at the end of your prompt and <default-title> is the title that screen should use when the shell is sitting at a prompt. For the second part, put a null title-string escape sequence in your prompt; just a <esc>k<esc>\.

Here's a concrete example. Suppose your bash prompt is “\u@\h:\w\$ ”. Unless you su to root, the string “$ ” will always be at the end of your prompt. So you put this in your .screenrc:

shelltitle "$ |bash"

and this in your .bashrc or .profile:

export PS1='\[\033k\033\\\]\u@\h:\w\$ '

Please note the use of single quotes. Also, if you want to use it with a bash prompt that spans several lines you have to put it on the last line. For example:

export PS1='\[\033k\033\\\]'
export PS1="\n\u@\h:\w\n"$PS1'\$ '

As a special case, if the <default-title> from above ends in a colon, the name of the currently running program will be appended to the default title instead of replacing it. In the above example, with shelltitle “$ |bash”, if you run pine, the title will change from “bash” to “pine”, and back to “bash” when you exit pine. If you use shelltitle “$ |bash:”, the title will change from “bash:” to “bash:pine” and then back to “bash:”.


User Tools