Site Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

title_examples [2010-01-21 23:47]
asciiphil Link to commands.
title_examples [2021-02-19 19:49]
Line 1: Line 1:
-===== Title Examples ===== 
- 
-Each screen window has a title.  The title is visible in the window display (from the ''[[commands:windows]]'' command or ''[[commands:windows|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 ''[[commands:shelltitle]]'' command in your .screenrc.  That may be overridden by the ''-t'' option of the ''[[commands:screen]]'' command, the title-string escape sequence (''<esc>k//<new-title>//<esc>\''), and the ''[[commands:title]]'' command (bound to ''[[commands:title|C-a A]]''). 
- 
-==== Simple examples ==== 
- 
-In .screenrc, set the default title of all windows to "cardamom": 
- 
-<code> 
-shelltitle "cardamom" 
-</code> 
- 
-In .screenrc, from screen's command line, or from a shell inside screen, make a new window with the title "anise": 
- 
-<code> 
-screen -t anise 
-</code> 
- 
-The escape sequence can be used from any program to set the title.  Here are examples for the command line: 
- 
-<code> 
-echo -ne '\ekcommand-line\e\\' 
-</code> 
- 
-a bash shell prompt: 
- 
-<code> 
-export PS1='\[\033kbash\033\\\]$ ' 
-</code> 
- 
-and, just for fun, Emacs Lisp: 
- 
-<code> 
-(send-string-to-terminal "\ekemacs\e\\") 
-</code> 
- 
- 
-==== Setting the title to the host you ssh'd into ==== 
- 
-A nice solution may be found at http://www.tenshu.net/screen_ssh/ 
- 
-See also http://lists.gnu.org/archive/html/screen-users/2008-07/msg00016.html 
- 
- 
-==== 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: 
- 
-<code> 
-alias postcmd 'echo -ne "^[k\!#:0^[\\"' 
-</code> 
- 
-In zsh, it's the shell function ''preexec'': 
- 
-<code> 
-preexec () { 
-  echo -ne "\ek${1%% *}\e\\" 
-} 
-</code> 
- 
-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: 
- 
-<code> 
-shelltitle "$ |bash" 
-</code> 
- 
-and this in your .bashrc or .profile: 
- 
-<code> 
-export PS1='\[\033k\033\\\]\u@\h:\w\$ ' 
-</code> 
- 
-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: 
- 
-<code> 
-export PS1='\[\033k\033\\\]' 
-export PS1="\n\u@\h:\w\n"$PS1'\$ ' 
-</code> 
- 
-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