While I work on command line, mostly remotely, there’re two tools I like very much: settitle and screen. The first one change the terminal titles, so I can know which one to choose when switching among my X windows. The other, screen, well, have got lots of articles about it. It enables me to run several shells inside one terminal window, and keep them running even if I logout from the remote system.
However there’s one thing I don’t like: settitle won’t work within screen. There are two things settitle could be expect to do within screen: 1. set the terminal title 2. set the screen window name But currently it won’t do either.
Personaly I’d like it to do (2). So here’s the script I made after some document reading:
The script should set screen window name if runned inside screen, and set the terminal title if runned outside screen.
First all I’ll need to find out if the script is running inside or outside screen. Screen set $TERM to “screen” inside it, I could check TERM. However, sometimes I change $TERM, for some applications. So I’ll need another way:
In ~/.screenrc, I add a line
This way inside the screen session an enviroument variable INSCREEN is set to “yes”. And ofcause, outside screen it is not set.
And here’s the script I got:
# set terminal title in X or set window name in screen. Choose
# solution 1 or solution 2 as you like
# solution 1
# you’ll need to add
# setenv INSCREEN yes
# in .screenrc to make this work. Useful if you change TERM within screen
IAMINSCREEN=`printenv INSCREEN`
if [ -z “$IAMINSCREEN” ]; then
IAMINSCREEN=”no”
fi
# # solution 2
# # This works without .screenrc modification, but remember not to
# # change TERM within your screen session
# THETERM=`printenv TERM`
# if [ -z “$THETERM” ]; then
# IAMINSCREEN=”no”
# else
# if [ $THETERM = “screen” ]; then
# IAMINSCREEN=”yes”
# else
# IAMINSCREEN=”no”
# fi
# fi
if [ ${IAMINSCREEN} = “yes” ]; then
print -n “\033k$1\033\\”
else
# # /usr/local/bin/settitle $1
# # use this when settitle binary is not available
print -n “\033]0;$1\007″
fi
Note I have also the $TERM check solution in it, and commented out. Choose one you like. And wish this useful.
Post a Comment
You could use <code type="name"> to get your code colorized