Search code examples
perlterminalansi-escape

ANSI sequence to change terminal name


I use a bash script (konsole-name.sh) to change a terminal name, like this:

#!/usr/bin/bash
echo -en "\e]30;$1\a"

and I wanted to use the same method from a perl script that I use to check the GPU temperature, so that it updates periodically the window title.

Yet I didnt find a way. I tried both this:

$comm='echo -en "\e]30;T=$t\a"';
`$comm`;

and this, using my bash script:

$comm="konsole-name.sh T=$t";
`$comm`;

there is some way to do it?


Solution

  • The console escape sequences work by printing text to the terminal. In your case, the backticks gobble up the output of the script.

    Most likely you just want print "\e]30;$1\a"; from within Perl:

    my $title = "Fancy terminal title";
    print "\e]30;${title}\a";