Site Tools


Differences

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

Link to this comparison view

Next revision
Previous revision
title_examples [2005-01-05 16:28]
209.251.43.194
title_examples [2021-02-19 19:49] (current)
Line 1: Line 1:
-===== Titles (naming windows) =====+====== 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 names as well as numbers to specify windows for many screen commands.+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 ''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'').+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 ====+===== Simple examples =====
  
 In .screenrc, set the default title of all windows to "cardamom": In .screenrc, set the default title of all windows to "cardamom":
Line 38: Line 38:
  
  
-==== Setting the title to the name of the running program ====+===== 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". 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".
Line 46: Line 53:
 <code> <code>
 alias postcmd 'echo -ne "^[k\!#:0^[\\"' alias postcmd 'echo -ne "^[k\!#:0^[\\"'
 +</code>
 +
 +On non-Linux systems like (Free)BSD or Solaris you may use the POSIX version with printf:
 +<code>
 +alias postcmd 'printf "\033k\!#\033\\"'
 </code> </code>
  
Line 52: Line 64:
 <code> <code>
 preexec () { preexec () {
-  echo -ne "\ek${(s: :)1[1]}\e\\"+  echo -ne "\ek${1%% *}\e\\"
 } }
 </code> </code>
Line 68: Line 80:
 <code> <code>
 export PS1='\[\033k\033\\\]\u@\h:\w\$ ' 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> </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:". 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