Terminal titles and line wrap
On a couple of remote systems, I've been annoyed by line wrap problems in the terminal. As in command lines would wrap at a strange place, and then cursor movement is all messed up, and I'd have to count (not look) when editing a line.
Today I finally figured out what was going on: prompt version skew!
On those particular systems, I'd at some point set my prompt to put the hostname and cwd into title bar of the local terminal application. I was using an invocation like PS1='\u@\h:\w\$ \e]2;\u@\H \w\a'. To set the prompt to username@host:cwd$ on the command line, and something similar in the title.
But looking at the faq this morning, I noticed it lists \[ and \] as quoting non-printing characters. I thought hmm...and added them around the xterm escape sequence. Sure enough, the problems went away.
I swear this used to work, but apparently now the terminal somehow counts the non-printing characters when calculating line lengths, and the square bracket quoting makes it not do that. Some kind of hack for i18n?
Most recipes suggest \033]2;<title goes here>\007 for setting the title, but bash supports \e for the escape character and \a for the bell, which delimit the xterm controls. You can also use \$ for a prompt character that switches based on whether you're root. So a less noisy suggestion is something like:
if [ "$PS1" ]; then if [ "$BASH" ]; then PS1='\u@\h:\w\$ \[\e]2;\u@\H\a]' else if [ "`id -u`" -eq 0 ]; then PS1='# ' else PS1='$ ' fi fi fi
In other news, setting the "Delete key sends backspace" option on the MacOS X terminial no longer seems to be necessary for reasonable remote editing, which is nice because it makes backspace not work at all on local apps. fn-delete for delete-char-right (delete instead on backspace on US keyboards in linux) still doesn't work locally though.