|
V
|
|
ASIC/FPGA Design and Verification Out Source Services
Some tips for controlling the xterm title.
This document suggest a nice way to control the title of an XTERM in assorted
shells such as tcsh, csh and bash. While setting the title statically is
simple, dynamically it is a bit more complicated. I found it convenient to name
each of my terminals. Since tasks do change, a dynamic
control is helpful.
Static is simple as shown below via an alias for tcsh.
alias my_xterm 'xterm -fn 10x20 -bg white -fg red3 -T "\!:1"'
Colors and XTERM size are also statically set by this alias.
For a bash shell it is fairly easy, by controlling a system environment
variable.
PS1="\[\033]0;\u@\h: $1 \007\]bash\\$ "
For a tcsh it is also not too difficult as well. I did it by adding the following
alias.
alias term_name 'echo -n "\033]0;\!:1\007"'
To change the title simply, fire up the alias with an argument.
The most difficult effort, for me to achieve title-control, was on csh. Again as seen in other scripts
in this site, when it is tough, I don't try to find the best script, but rather
a script or set of scripts that merely do the job.
After some "playing" with the command, I have found out that this configuration works well. I invoke tsch to do a command
and quit.
tcsh -c 'setenv Tmp "my title name";echo -n "\033]0;$Tmp\007"'
I had hard time to put it into an alias and therefor decided to do it in
multiple, relatively easy, steps.
First I put an alias that calls a perl script.
alias term_name 'perl ~/bin/term_name.pl \!:1; ~/bin/term_name_pl.unx'
Second, please note, that perl script generates an executable file and places
the file in a default bin directory (~/bin). This executable file is later
called by the second part of the alias.
Last comes the perl script itself:
#!/bin/perl
open(FPW, ">term_name_pl.unx");
$cmd="tcsh -c \'setenv Tmp \"" . $ARGV[0] . "\";echo -n \"\\033]0;\$Tmp\\007\"\'
print FPW ("$cmd\n");
system("mv -f term_name_pl.unx ~/bin");
system("chmod u+x ~/bin/term_name_pl.unx");
In addition to a unique name, that one may want to attach to a terminal, it might also be handy to add the load average of the station. To do it just include the following information.
#!/usr/bin/perl
open(LOAD,"/proc/loadavg") || die "Couldn't open /proc/loadavg: $!\n";
my @load=split(/ /,);
close(LOAD);
print "$host: $load[0] $load[1] $load[2]"
The script can use an endless loop and put in background, so title is constantly updated with load average info. An optional parameter can be added to force script exit. This a process number of the father xterm:
The terminal name script is invoked like this:
perl ~/bin/term_name_loop.pl my_name 9997&
So once the xterm is killed, the terminal name script will sense it and quit.
...
$n=scalar @ARGV;
if($n > 1) {#this parameter is optional
$usr_name=`whoami`; chomp($usr_name);
$cmd="ps -aefH | grep " . $usr_name;
$pid_all=`$cmd`;
$search=" " . $ARGV[1] . " ";
$id0=index($pid_all, $search);
$id1=index($pid_all, "xterm");
#condion to die - no father xterm process
if($id0 == -1 || $id1 == -1) {exit(0);}
if($id0 > $id1) {exit(0);}
}
...
The script also prints the number of hours that it ran:
...
$time_hr=(time - $^T)/3600;
$loadv="number of cpus " . $cpu_num . " " .$load[0] . " " . $load[1] . " " . $load[2] . " " . $dateS . " " . $time_hr . "H ";
open(FPW, ">term_name_pl_loop.unx");
$term_name=$ARGV[0] . "_" . $loadv;
$cmd="tcsh -c \'setenv Tmp \"" . $term_name . "\";echo -n \"\\033]0;\$Tmp\\007\"\'";
...
This document suggest a nice way to control the title of an XTERM in assorted
A complete script example can downloaded from the following link:
script .
To control the prompt I use the following settings:
#prompt
set prompt = "-- %T %n %~ -- \n$ "
|
|
|
Search This Site
Feedback This Site
new pages on this site
|
|