Setting the Terminal Title in Gnu Screen


Setting the Terminal Title in Gnu Screen
I often have multiple terminals open and screen running in each one. I then try to group all my work for a particular project in that terminal. While I am trying to limit the amount of multitasking and concentrate on one thing at a time, I might leave a terminal/screen session up for days and when I come back I can jump right back where I started.
The downside to this is using cmd-tab (or alt-tab with Witch) gives me a list of several terminals each with the title screen - bash - username or maybe screen - vim -username… not very helpful. What I want is to set a name for each terminal and display it in the terminal’s title. If I anticipate this before launching screen, I can accomplish it with screen -t <My Title>. Once I am inside a session though, you need to change each window’s title/name for this to work.
After searching the web and a bunch of trial-and-error, I found a solution. The first part is pretty well documented. Changing the name for all windows and the default for new windows took quite a bit a tinkering.
Setup screen (via .screenrc) to update your terminals title bar and include the name of the current window.
1<code># Add to .screenrc2termcapinfo xterm* 'hs:ts=\E]0;:fs=\007:ds=\E]0;\007'3defhstatus "screen ^E (^Et) | $USER@^EH"4hardstatus off</code>The escape string ^Et in the defhstatus is converted into the current window’s name/title.
Create a function to update the name of each screen window.
01<code># Add to .bashrc
02# Set the title of a Terminal window
03function settitle() {
04 if [ -n "$STY" ] ; then         # We are in a screen session
05  echo "Setting screen titles to $@"
06  printf "\033k%s\033\\" "$@"
07  screen -X eval "at \\# title $@" "shelltitle $@"
08 else
09  printf "\033]0;%s\007" "$@"
10 fi11}</code>
You can change the name of the current window by pressing Ctrl-a A, but we want to change the title for all the windows. screen -X eval will execute each of its arguments in the current screen.
The command at \#title will execute the title command in all the windows (the \ before # is required otherwise # will be interpreted as the beginning of a comment). The shelltitle command will ensure that any newly created windows use this title.

Comments

Popular posts from this blog

How to prepare your PC for the Windows 10 upgrade Source: WC

Top 5 Japanese Anime (Cartoons)

TOP FREE ANTIVIRUS