LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 10-10-2012, 11:49 AM   #1
sirEgghead
LQ Newbie
 
Registered: Oct 2012
Location: Mobile, AL
Distribution: CentOS 6.3, Debian 6
Posts: 3

Rep: Reputation: Disabled
Question 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
 
Old 10-10-2012, 01:38 PM   #2
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,908

Rep: Reputation: 356Reputation: 356Reputation: 356Reputation: 356
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.

Last edited by bigrigdriver; 10-10-2012 at 01:41 PM.
 
Old 10-10-2012, 02:08 PM   #3
sirEgghead
LQ Newbie
 
Registered: Oct 2012
Location: Mobile, AL
Distribution: CentOS 6.3, Debian 6
Posts: 3

Original Poster
Rep: Reputation: Disabled
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:~]#"
 
Old 10-10-2012, 02:45 PM   #4
wpeckham
LQ Guru
 
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, VSIDO, tinycore, Q4OS,Manjaro
Posts: 5,587

Rep: Reputation: 2687Reputation: 2687Reputation: 2687Reputation: 2687Reputation: 2687Reputation: 2687Reputation: 2687Reputation: 2687Reputation: 2687Reputation: 2687Reputation: 2687
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?
 
Old 10-10-2012, 02:50 PM   #5
sirEgghead
LQ Newbie
 
Registered: Oct 2012
Location: Mobile, AL
Distribution: CentOS 6.3, Debian 6
Posts: 3

Original Poster
Rep: Reputation: Disabled
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

Last edited by sirEgghead; 10-10-2012 at 02:51 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
New Year's gift for you: A variable-length bash prompt David the H. Linux - General 9 03-21-2014 06:04 AM
[SOLVED] Make Bash prompt look like Windows C:\ prompt -- *PROBLEM* arkadios Linux - General 5 07-24-2012 11:29 AM
Variable length console prompt statquant Linux - General 7 07-15-2010 05:55 PM
getting custom PWD in bash prompt techrolla Linux - Software 2 08-09-2004 12:39 AM
Maximize Putty to command prompt? KePSuX General 0 08-15-2003 03:05 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 12:45 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration