views:

430

answers:

3

Hi,

is it possible to set the Screen-Title with an shellscript?

i thought about something like sending the key commands "Strg+A Shift-A Name "

I searched for about an hour only how to emulate keystrokes in an shell-script - but didnt find the answer.

Thanks for Help!

Beerweasle

+3  A: 

You can set the screen / xterm title using the following lines:

#!/bin/bash

mytitle="Some title"
echo -e '\033k'$mytitle'\033\\'
Shirkrin
+3  A: 
set_screen_title ()
{
    echo -ne "\ek$1\e\\"
}
Randy Proctor
+2  A: 

From http://www.faqs.org/docs/Linux-mini/Xterm-Title.html#s3

xterm escape sequences

Window and icon titles may be changed in a running xterm by using XTerm escape sequences. The following sequences are useful in this respect:

  • ESC]0;stringBEL -- Set icon name and window title to string
  • ESC]1;stringBEL -- Set icon name to string
  • ESC]2;stringBEL -- Set window title to string

where ESC is the escape character (\033), and BEL is the bell character (\007).

Printing one of these sequences within the xterm will cause the window or icon title to be changed.

Note: these sequences apply to most xterm derivatives, such as nxterm, color-xterm and rxvt. Other terminal types often use different escapes; see the appendix for examples. For the full list of xterm escape sequences see the file ctlseq2.txt, which comes with the xterm distribution, or xterm.seq, which comes with the rxvt distribution.

Printing the escape sequences

For information that is constant throughout the lifetime of this shell, such as host and username, it will suffice to simply echo the escape string in the shell rc file:

    echo -n "\033]0;${USER}@${HOST}\007"

should produce a title like username@hostname, assuming the shell variables $USER and $HOST are set correctly. The required options for echo may vary by shell (see examples below).

For information that may change during the shell's lifetime, such as current working directory, these escapes really need to be applied every time the prompt changes. This way the string is updated with every command you issue and can keep track of information such as current working directory, username, hostname, etc. Some shells provide special functions for this purpose, some don't and we have to insert the title sequences directly into the prompt string. This is illustrated in the next section.

Espo
Screen however appears to ignore this completely, although I've found snippets using both "\ekTITLE\e\\" and "\e]0;TITLE\a" (the latter without any use apparently).Maybe this is related to the screen "hardstatus" setting though - I am using the following there: hardstatus string "SCREEN @ %H: %-n - %t" (%t refers to window title)
blueyed