Tuesday, February 2, 2010

An Update on Prompts

Well, the prior prompt had a problem.

The main symptom was that the command line would wrap before reaching the right edge of the terminal window (which is annoying but not terrible), but in wrapping, it would only issue the carriage return, not the line feed, so that the rest of the line was commingled with the prompt and the beginning of the line. That was beyond annoying. Google Fu 'os x terminal prompt mac \e[ confuses' found this page, which linked to this one which explained the problem.

In short \e opens an escape sequence, but does not close it. The fix is to replace \e with \[\033 and close the entirety with \]. That leaves a remarkably unreadable definition of PS1:

PS1='\[\033]2;\u@\h:\w\a\[\033[36;40m\]\u@\h:\w \$ \[\033[0m\]'

I've also noticed that logging in from a linux virtual terminal in text mode doesn't handle the system escape to set the title bar — \[\33]2 — very well. I've added a conditional that checks SSH_TTY, and that seems to work, but I know there are probably more cases that I haven't considered.

One last thing, for some reason, no matter what I do, su does not read .bashrc. I've tried su -, su -l, creating a .bash_login. I'm stumped.

No comments:

Post a Comment