Differences between revisions 1 and 2
Revision 1 as of 2007-05-02 23:45:33
Size: 596
Editor: redondos
Comment:
Revision 2 as of 2007-05-10 01:20:16
Size: 701
Editor: ool-4577d016
Comment:
Deletions are marked like this. Additions are marked like this.
Line 14: Line 14:

Refer to the Wikipedia article for [http://en.wikipedia.org/wiki/ANSI_escape_code ANSI escape codes].

Anchor(faq53)

I have a fancy prompt with colors, and now bash doesn't seem to know how wide my terminal is. Lines wrap around incorrectly.

You must put \[ and \] around any non-printing escape sequences in your prompt. Thus:

BLUE=$(tput setaf 4)
PURPLE=$(tput setaf 5)
BLACK=$(tput setaf 0)
PS1='\[$BLUE\]\h:\[$PURPLE\]\w\[$BLACK\]\$ '

Without the \[ \], bash will think the bytes which constitute the escape sequences for the color codes will actually take up space on the screen, so bash won't be able to know where the cursor actually is.

Refer to the Wikipedia article for [http://en.wikipedia.org/wiki/ANSI_escape_code ANSI escape codes].

BashFAQ/053 (last edited 2022-09-14 02:03:48 by emanuele6)