develooper Front page | perl.fwp | Postings from September 2001

Fun with xterm window titles, or Yet Another golf challenge

Thread Next
From:
Craig S. Cottingham
Date:
September 6, 2001 23:02
Subject:
Fun with xterm window titles, or Yet Another golf challenge
Message ID:
200109070601.XAA11834@smtpout.mac.com
On the Mac OS X Unix mailing list (<X-
Unix@lists.themacintoshguy.com>), what started out as (IIRC) an 
innocent question about xterm escape sequences has become a 
hellish exercise in feeping creaturism. The line was crossed 
when someone asked:

> E.g., if pwd is
>
>   /Users/me/Documents/LearnC/FirstSteps
>
> then I'd like
>
>   .../LearnC/FirstSteps
>
> to display in the title bar (or on the prompt).

To which I replied:

> Okay. Here's one way to do it, but I don't think you're going 
> to like it. :-)
>
> 	export PROMPT_COMMAND="perl -e 
> '@d=split/\//,qx(pwd);@d=(q(...),@d[\$#d-1..\$#d])if(@d>3);chomp@d;print 
> join(q(/),@d),q( )'"
>
> (That should all be one line, in case various mail handlers 
> happen to wrap it.) Figuring out how to turn that monstrosity 
> into an xterm sequence that sets the window title is left as an 
> exercise for the reader.... No, apparently I'm a glutton for 
> self-abuse, because here it is:
>
> 	export PROMPT_COMMAND="perl -e 
> '@d=split/\//,qx(pwd);@d=(q(...),@d[\$#d-1..\$#d])if(@d>3);chomp@d;print 
> qq(\033]0;).join(q(/),@d).qq(\007)'"

Can anyone see a way the second script can be condensed? I don't 
fancy myself a golf expert (either in Perl or in real life), but 
I can't see any way to shorten it, save maybe for using regexes 
(which, frankly, I'm too tired at the moment to contemplate).

You are allowed to assume that you're running bash on a 
Unix-like system, interacting via xterm or some other 
application that accepts xterm escape sequences.

--
Craig S. Cottingham
cottingham@mac.com
PGP key available from: 
<http://pgp.ai.mit.edu:11371/pks/lookup?op=get&search=0xA2FFBE41>
ID=0xA2FFBE41, fingerprint=6AA8 2E28 2404 8A95 B8FC 7EFC 136F 
0CEF A2FF BE41

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About