-   Linux - General (
-   -   Custom Bash Prompt Length PuTTY (

sirEgghead 10-10-2012 12:49 PM

Custom Bash Prompt Length PuTTY
I setup a custom bash prompt on one of my servers. When I log into the server via putty and the window is at the default size (not maximized), the prompt is messed up. The cursor is also in the middle of the prompt. As soon as I maximize the window, the prompt is fine.

My prompt is:

MyDateTime="\n\e[$BBlack[$Red\d \A$BBlack]\e[m"

It is supposed to look like:

[Wed Oct 10 11:41][root:~]#
But when it is messed up, it looks like:

~]#d Oct 10 11:47][root:~
The cursor starts on the 'd' right after the '#'. I've tried a few things such as removing '$MyDateTime' from PS1 and typing it out manually. Also removed the '\n\r'. No change in results. Also please note that the window width is over three times the length of the prompt, so I wouldn't think it is getting too close. Maybe the prompt is too long anyway? Any ideas?


bigrigdriver 10-10-2012 02:38 PM


You have an unmatched square bracket in the prompt:


Missing one ] in the prompt.

You can learm more about it in the BASH PROMPT HOWTO.

sirEgghead 10-10-2012 03:08 PM

Not to sound rude, but what does that have to do with my prompt working with putty in full screen and not when it's not?

I could have 15 open brackets in my prompt and it not affect it. Click on that link that you posted and click on colors. All of the color escape codes have open brackets in them. The only close brackets in my prompt are purely aesthetic, ie: "[Wed Oct 10 11:41][root:~]#"

wpeckham 10-10-2012 03:45 PM

Just for giggles...
Could you take your line

and try it like this

to see what difference that makes?

sirEgghead 10-10-2012 03:50 PM

Ok, well I added \] to all of my color codes, including my "stop color" and I still have the same problem. I added one escaped open bracket to the colors and now I am good.

For instance, before BBlack was:

Now it is:

However, that still leaves us with a 2:1 offset of non-aesthetic open vs close brackets. But either way, it's working fine.

Thanks for looking at it.


All times are GMT -5. The time now is 08:19 AM.