Movatterモバイル変換


[0]ホーム

URL:


GNU screen

GNU screen

Site Tools

Trace:title_examples

Title Examples

Each screen window has a title. The title is visible in the window display (from thewindows command orC-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 theshelltitle command in your .screenrc. That may be overridden by the-t option of thescreen command, the title-string escape sequence (<esc>k<new-title><esc>\), and thetitle command (bound toC-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 aliaspostcmd. 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 functionpreexec:

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, withshelltitle “$ |bash”, if you run pine, the title will change from “bash” to “pine”, and back to “bash” when you exit pine. If you useshelltitle “$ |bash:”, the title will change from “bash:” to “bash:pine” and then back to “bash:”.


User Tools

title_examples.txt · Last edit was 2021-02-19 19:49 (external edit)

Warning: Undefined array key "gnugpl2+" in/home/public/screen/inc/template.php on line1532

[8]ページ先頭

©2009-2025 Movatter.jp