Craig S. Cottingham wrote:
> > 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).
Hm, bash expands `` inside double-quoted strings, doesn't it? Otherwise you
could replace qx(pwd) by `pwd` (but qx(pwd) and \`pwd\` have the same
length, so it's no win). You can replace "\$#d-1..\$#d" by "\$#d-1,\$#d"
since you have exactly two elements, or make it even shorter with "-2,-1". I
was going to say you could replace "split/\//" with "split'/'" to remove the
backslash, but you can't use either single or double quotes since both sets
are already open. You can also reaplce \033 and \007 by \33 and \7, and
"if(@d>3)" by "if@d>3". And you could probably replace
print qq(\33]0;).join(q(/),@d).qq(\7)
with
\$\"=q(/);print+qq(\33]0;@d\7)
...hang on, ESC is \e and BEL is \a, so you can make that
\$\"=q(/);print+qq(\e]0;@d\a)
for one fewer character and a litle extra obfuscation.
So here's my attempt:
export PROMPT_COMMAND="perl -e
'@d=split/\//,qx(pwd);@d=(q(...),@d[-2,-1])if@d>3;
chomp@d;\$\"=q(/);print+qq(\33]0;@d\7)'"
I didn't have a bash handy to try it out, but when I used eval "perl -e
'...'" in a ksh running under xterm, it worked as expected when I tried it
out in a couple of directories. (The eval "" solely to provide double quotes
around the outside to make sure I didn't mess up the quoting; of course, I
had to re-run the command manually after changing directories. Oh, and I put
it all in one line when I tried it; the wrapping is only for readability in
this message.)
Cheers,
Philip
--
Philip Newton <[EMAIL PROTECTED]>
All opinions are my own, not my employer's.
If you're not part of the solution, you're part of the precipitate.