From the Archives 2

From December 2, 2005:

More Eterm. Turns out the next item on the agenda is not to get the End key working, but to get something more helpful than “Eterm” to appear in the title bar. This is where we start to get into some dark magic. Here’s the prompt I’m using right now, after some hair pulling and tweaking:
PS1=”\[\e]2;\u@\h \W\a\][\u@\h \W]\$ “
That’s just craziness. How do we decipher this and bend it to our will? I found a very helpful site by IBM here.

Just for grins, I shall unravel this statement. first, let’s expand some thing.
\u = your username
\h = first part of your hostname
\W = the name of the the current working directory
\$ = $ if you are not root, # if you are.

Basically what we have here is the same prompt twice. First it is wrapped in \[\e]2; and \a\]. Then we have the same thing again, plus the \$. I’ll get back to this, but what we basically get is “[username@hostname current-dir]$”. For example, “[josterpi@gandalf docs]$ “

Get back to the first part: \[\e]2;TITLEBAR\a\] puts TITLEBAR in the title bar of the terminal. Exactly what I wanted to do. I ran into a very wierd problem though. As I was typing commands, it would wrap around onto the same line, so that I was writing over what I had just writting. Very annoying. It turns out that the problem I had was that I wasn’t wrapping the title bar section in \[ and \]. What the escaped brackets do is indicate to the shell that what is in the brackets should no be considered when calculating word wrapping, which is what I was having trouble with. That is, the stuff between the brackets is non-printing. We would have to use brackets if if we were using escape sequences for color or whatever else.

Next I’ll have to explain how I was able to use escape sequences to dynamically toggle my Eterm from black-on-white to white-on-black using escape sequences and key bindings.

Also, I’ve done some neat stuff with key bindings in fluxbox and figuring out the keycodes for a couple of my IBM thinkpad specific keys. More later…or not.

Leave a Reply