This is a short bit of code to show how you can use perl to change the title of your xterm on the fly. It works with Tera Term as well, and probably others.
#!/usr/bin/perl -w use strict; print("\e]0;@ARGV\7");
That simple program will change the icon and title to the arguments from the command line.

The important part is the "\e]0" and "\7". The first tells the terminal that the following text is meant to be the title. The \7 terminates the title string. Also "\e]1" sets only the icon name, and "\e]2" sets only the title.

Replies are listed 'Best First'.
Re: How to change an xterm title on the fly
by stefan k (Curate) on Oct 22, 2001 at 18:39 UTC
    Of course one could push it further and make the xterm title display the current path. Actually this is no perl code but I really don't see the need for perl here.
    # The Prompt unset PROMPT_COMMAND case $TERM in xterm*) TITLEBAR='\[\033]0;\h:\w\007\]' ;; *) TITLEBAR='' ;; esac PS1="${TITLEBAR}\u@\[\033[1;34m\]\h\[\033[0m\]:\W> " export PS1 PS2
    (to put into your ~/.bashrc - yeah, we're really OT here ;-)

    Regards... Stefan
    you begin bashing the string with a +42 regexp of confusion

      Well... my real purpose was to show the basics of how to change it for perl (since this is PerlMonks :) I leave it up to the user to decide what they want to do with it. I was using it to put the current song from my mp3 jukebox script in the title...

                      - Ant
                      - Some of my best work - (1 2 3)

Re: How to change an xterm title on the fly
by jirwin (Monk) on Dec 29, 2001 at 00:25 UTC
    I like it. Clients won't remember the codes, but they will remember chxterm.pl text. jirwin
Re: How to change an xterm title on the fly
by jmcnamara (Monsignor) on Feb 14, 2003 at 16:29 UTC

    I was just about to post this snippet. Just as well I checked grinder's archive first. :-)

    Anyway, here was my version:

    # Change the title of your xterm perl -e 'print "\c[];@ARGV\a"' Some title here

    --
    John.