LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Custom Bash Prompt Length PuTTY (https://www.linuxquestions.org/questions/linux-general-1/custom-bash-prompt-length-putty-4175431520/)

sirEgghead 10-10-2012 11:49 AM

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:
Code:

MyDateTime="\n\e[$BBlack[$Red\d \A$BBlack]\e[m"
PS1="$MyDateTime\e[$BBlack[$Red\u$BBlack:$Red\W$BBlack]#\e[m"

It is supposed to look like:
Code:

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

~]#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?

Thomas

bigrigdriver 10-10-2012 01:38 PM

Quote:

PS1="$MyDateTime\e[$BBlack[$Red\u$BBlack:$Red\W$BBlack]#\e[m"
You have an unmatched square bracket in the prompt:
[$BBlack[$Red\u$BBlack:

:$Red\W$BBlack]

Missing one ] in the prompt.

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

sirEgghead 10-10-2012 02: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 02:45 PM

Just for giggles...
 
Could you take your line
Code:

PS1="$MyDateTime\e[$BBlack[$Red\u$BBlack:$Red\W$BBlack]#\e[m"
and try it like this
Code:

PS1="${MyDateTime}\e[$BBlack[$Red\u$BBlack:$Red\W$BBlack]#\e[m"
to see what difference that makes?

sirEgghead 10-10-2012 02: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:
Code:

BBlack='\e[1;30m'
Now it is:
Code:

BBlack='\[\e[1;30m\]'
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.


Thomas


All times are GMT -5. The time now is 05:42 AM.