home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 February / CHIP_2_98.iso / doc / HOWTO / mini / Xterm-Title < prev    next >
Text File  |  1996-10-27  |  5KB  |  143 lines

  1.  
  2. Xterm-Title mini-HOWTO                     Winfried Trⁿmper <winni@xpilot.org>
  3. ----------------------                     Version 1.3             22 Oct 1996
  4.  
  5.  
  6.  
  7. "Isn't this boring?" most people will ask. I just do a
  8.  
  9.     xterm -T "Rent this place for your advertisement" \
  10.           -n "The name of the icon could be yours, too" &
  11.  
  12.  
  13. to place arbitary strings into the titlebar of the xterm. Ok, that's
  14. right but you may want to change it after startup ...
  15.  
  16. To change the title while the xterm is running, you just send a
  17. special sequence of characters to it. Such a special sequence is named
  18. "escape sequence" and usally not displayed on the screen but causing
  19. certain actions. 
  20. For example, if you press <ctrl-v> <Esc> <c> <Enter>, your xterm
  21. should reset (e.g. clear the screen). The <ctrl-v> and <enter> are only
  22. needed to make the bash printing the actual sequence <esc> <c>.
  23.  
  24. Note that I refer to keystrokes by enclosing the label of that key
  25. by <>.
  26.  
  27. Now, to change the titlebar and icon of the xterm you just use the
  28. escape-sequences
  29.  
  30.         <esc> <]> <2> <;>    sets a new title
  31.         <esc> <]> <1> <;>    sets a new icon-name
  32.  
  33.  
  34. To send those sequences to the xterm, we no longer type them on the
  35. command-line, but we use the program `echo':
  36.  
  37.     echo -e "\033]2; You can rent this place for a commercial. \007"
  38.  
  39. As you might have guessed `\033' is the octal representation of the
  40. escape-character and '-e' enables this syntax.
  41. You must terminate the string that should show up in the title with a
  42. <ctrl-g> aka "the lovely beep".
  43.  
  44.  
  45. One useful application for those features is to move the information
  46. usally found in the command-prompt into the xterm-title: lets assume
  47. you have defined you command-prompt as
  48.  
  49.         export PS1='\u@\h:\w> '
  50.  
  51. so it looks like
  52.  
  53.         winni@FeilSurf:~/mail>
  54.         
  55. What happens, if you change to the directory "/afs/rrz.uni-koeln.de
  56. /pub/packages/linux/kernel/v2.0"? Right, the prompt gets longer and
  57. leaves less space for typing commands:
  58.  
  59.         winni@FeilSurf:/afs/rrz.uni-koeln.de/pub/packages/linux/kernel/v2.0>
  60.  
  61.  
  62. This is odd. But - if you put this information into the title-bar,
  63. everything is fine:
  64.  
  65.         export PS1='\033]2; \u@\h:\w \007bash> '
  66.  
  67. The command above echoes the needed escape-sequences and leaves as
  68. prompt:
  69.  
  70.         bash> _
  71.  
  72.  
  73. Unfortunatly the maximum length of the value of PS1 is limited to
  74. somewhat around 60 (?) chars and so it's not suited in all
  75. cases. Another  idea is to re-define shell-builtins like "cd" to echo
  76. the escape-sequences but this has the ugly side-effect of a nervous
  77. title-bar when running shell-scripts ... (yes, every "cd" changes the
  78. title).
  79.  
  80. The most reliable approach seems to me the usage of the
  81. environment-variable "PROMPT_COMMAND". The content of this variable is
  82. executed after a program has finished and before the bash prompts at
  83. you again. The following is very useful in a networked environment
  84. with many xterms opened:
  85.  
  86.         export PROMPT_COMMAND='echo -ne "\033]2;$LOGNAME@$HOST     Directory: $PWD\007\033]1;$LOGNAME@$HOST\007"'
  87.  
  88.  
  89. ... especially when you look at the "window list" of your
  90. window-manager. And to make it perfect, we only set this variable when
  91. we are in an xterm:
  92.  
  93.         if [ "$TERM" = "xterm" -o "$TERM" = "xterm-color" -o \
  94.              "$TERM" = "rxvt"  -o "$TERM" = "vs100" ]
  95.         then
  96.           PS1='bash> '
  97.           PS2='bash>> '
  98.           PS3='bash>>> '
  99.           export PROMPT_COMMAND='echo -ne "\033]2;$LOGNAME@$HOST     Directory: $PWD\007\033]1;$LOGNAME@$HOST\007"'
  100.         fi
  101.  
  102.  
  103. Note that the prompt "bash> " makes the command-line somewhat more
  104. consistent because many programs put their name in the front (gnuplot,
  105. ncftp, gap, kash, ...).
  106. But even this has the drawback of messing up some programs that spawn
  107. up sub-shells like "ytalk". If you get bitten by it, issue 
  108.  
  109.         unset PROMPT_COMMAND
  110.  
  111.  
  112.  
  113. Happy Linuxing
  114. -Winfried Trⁿmper <winni@xpilot.org>
  115.  
  116.  
  117. CREDITS:
  118.  
  119.     Ville Voutilainen <vvoutila@raita.oulu.fi>
  120.         Noticed the ;s are missing from the escape-sequences in the
  121.         "first half" of the document.
  122.  
  123.  
  124. PS:
  125. ---
  126.  
  127. Don't ever use raw "escape-sequences" in any of your programs! Let the
  128. program ╗tput½ choose the right sequences from the environment-variable
  129. '$TERM' plus your symbolic description of the action to perform. See
  130. tput(1) for details (enter ╗man 1 tput½ at the command prompt).
  131.  
  132. The escape-sequences for the xterm-titlebar are the only exception from
  133. the above rule.
  134.  
  135.  
  136. PS2:
  137. ----
  138.  
  139. If you want to know the "escape-sequences" an xterms understand, then have
  140. a look at the sources for ╗rxvt½, it contains the file "xterm.seq" in the
  141. "doc/"-directory.
  142.  
  143.