#!/usr/bin/perl
#
# This is a script to return the current title of an xterm.

if ( ! $ARGV[0] ) {
	if ( ! $ENV{'WINDOWID'} ) {
		die "Not running under an xterm.\n";
	}
	$ARGV[0]=$ENV{'WINDOWID'};
}
open(PIPE, "xprop -id $ARGV[0] |") || die "Can't run xprop: $!\n";

while ( <PIPE> ) {
	chop;
	if ( /WM_NAME\(STRING\) = \"([^\"]*)\"/ ) {
		print "$1\n";
		exit(0);
	}
}
exit(1);
