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 -
… 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
usernamescreen -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.# Add to .screenrc
termcapinfo xterm* 'hs:ts=\E]0;:fs=\007:ds=\E]0;\007'
defhstatus "screen ^E (^Et) | $USER@^EH"
hardstatus offThe escape string
^Et
in thedefhstatus
is converted into the current window’s name/title.Create a function to update the name of each screen window.
# Add to .bashrc
# Set the title of a Terminal window
function settitle() {
if [ -n "$STY" ] ; then # We are in a screen session
echo "Setting screen titles to $@"
printf "\033k%s\033\\" "$@"
screen -X eval "at \\# title $@" "shelltitle $@"
else
printf "\033]0;%s\007" "$@"
fi
}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 commandat \#
will execute the
titletitle
command in all the windows (the\
before#
is required otherwise#
will be interpreted as the beginning of a comment). Theshelltitle
command will ensure that any newly created windows use this title.
0 komentar:
Posting Komentar