LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Enterprise Linux Forums > Linux - Enterprise
User Name
Password
Linux - Enterprise This forum is for all items relating to using Linux in the Enterprise.

Notices


Reply
  Search this Thread
Old 03-27-2012, 05:43 PM   #1
saeedamer
LQ Newbie
 
Registered: Feb 2011
Posts: 25

Rep: Reputation: 0
Command Prompt colors


Hi there

I am using Oracle Enterprise Linux 4.7 (and some servers have 5.x and 6.x but I guess it does not matter).

I want to be able to display some information in the unix command prompt in colors. I googled and tried this but it does not work:

Code:
export PS1='^[[0;32m^[[1m${HOST}:^[[1;33m${PWD}:^[[0;32m^[[m${ORACLE_SID}^[[0m> '
It just shows the whole string that is in quotes above (except for the env variables - it shows their value). For example, this is what I see:

Code:
^[[0;32m^[[1m:^[[1;33m/export/home/oracle:^[[0;32m^[[1mdevdb1^[[0m>

Could someone please help me with thisÉ

Thanks so much!
 
Old 03-27-2012, 05:58 PM   #2
lithos
Senior Member
 
Registered: Jan 2010
Location: SI : 45.9531, 15.4894
Distribution: CentOS, OpenNA/Trustix, testing desktop openSuse 12.1 /Cinnamon/KDE4.8
Posts: 1,144

Rep: Reputation: 217Reputation: 217Reputation: 217
Hi,

you should replace single ' quotes with double quotes ".
Code:
PS1="${USER}@${HOST}:"'${PWD}'"> "

good luck.

Last edited by lithos; 03-27-2012 at 05:59 PM.
 
Old 03-27-2012, 06:02 PM   #3
saeedamer
LQ Newbie
 
Registered: Feb 2011
Posts: 25

Original Poster
Rep: Reputation: 0
Thank you for your response. While I was waiting, I tried this:


Code:
Green="\033[32m"
Red="\033[31m"
Yellow="\033[33m"
Blue="\033[34m"
Bold=$(tput smso)
Normal=$(tput sgr0)
export PS1="[$Green\u@$Blue$(uname -n)]:$Normal\$PWD: [${Bold}${Red}\${ORACLE_SID}${Normal}] > "
Now it does show me some colors but what happens is when I press UP arrow (to see previous commands) it starts to scroll UP and shows the command on the line above the prompt line and then if i press up arrow again, it just keeps going up.

How to fix that please? I am using bash shell.

Last edited by saeedamer; 03-27-2012 at 06:04 PM.
 
Old 03-27-2012, 06:11 PM   #4
lithos
Senior Member
 
Registered: Jan 2010
Location: SI : 45.9531, 15.4894
Distribution: CentOS, OpenNA/Trustix, testing desktop openSuse 12.1 /Cinnamon/KDE4.8
Posts: 1,144

Rep: Reputation: 217Reputation: 217Reputation: 217
It's because the codes are not closed correctly.

Try this prompt:
Code:
PS1="(\[\e[33;1;44m\]$WINDOW\[\e[0m\]) [\H:\[\e[33;1;40m\]\u@\[\e[32;1m\]\w\[\e[0m\]] $\[\e[0m\]"
or try adding to the end of your line this :
Code:
\[\e[0m\]
It should "close" all the codes previously used,

and then modify it to suit yours.

You should check here
see that you need to set:
Code:
tput rmso

    Exit standout mode
which you don't use and maybe some others.

Last edited by lithos; 03-27-2012 at 06:16 PM.
 
Old 03-27-2012, 06:16 PM   #5
saeedamer
LQ Newbie
 
Registered: Feb 2011
Posts: 25

Original Poster
Rep: Reputation: 0
Thanks - how to close the color codes?

I tried your provided code and "(\[\e[33;1;44m\]$WINDOW\[\e[0m\]) " only displays "()". Looks like $WINDOW is not defined.

Could you please fix the one I posted? Or let me know how to close the color codes?

Thanks a bunch!
 
Old 03-27-2012, 06:19 PM   #6
saeedamer
LQ Newbie
 
Registered: Feb 2011
Posts: 25

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by lithos View Post
It's because the codes are not closed correctly.

Try this prompt:
Code:
PS1="(\[\e[33;1;44m\]$WINDOW\[\e[0m\]) [\H:\[\e[33;1;40m\]\u@\[\e[32;1m\]\w\[\e[0m\]] $\[\e[0m\]"
or try adding to the end of your line this :
Code:
\[\e[0m\]
It should "close" all the codes previously used,

and then modify it to suit yours.

You should check here
see that you need to set:
Code:
tput rmso

    Exit standout mode
which you don't use and maybe some others.
I tried

PS1="[$Green\u@$Blue$(uname -n)]:$Normal\$PWD: [${Bold}${Red}\${ORACLE_SID}${Normal}]\[\e[0m\] > "

but no difference - UP arrows still misbehaves.
 
Old 03-27-2012, 06:26 PM   #7
lithos
Senior Member
 
Registered: Jan 2010
Location: SI : 45.9531, 15.4894
Distribution: CentOS, OpenNA/Trustix, testing desktop openSuse 12.1 /Cinnamon/KDE4.8
Posts: 1,144

Rep: Reputation: 217Reputation: 217Reputation: 217
I would try yours like this:
Code:
add 
NORMALE=$(tput rmso)

export PS1="[$Green\u@$Blue \H]:$Normal \w: [${Bold}${Red}\${ORACLE_SID} $Normal $NORMALE] > "
It's pretty close to working I think, just not exactly what you want.

Last edited by lithos; 03-27-2012 at 06:29 PM.
 
1 members found this post helpful.
Old 03-27-2012, 06:29 PM   #8
saeedamer
LQ Newbie
 
Registered: Feb 2011
Posts: 25

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by lithos View Post
see that you need to set:
Code:
tput rmso

    Exit standout mode
which you don't use and maybe some others.
I tried this but still UP arrow does the same:

Code:
Green="\033[32m"
Red="\033[31m"
Yellow="\033[33m"
Blue="\033[34m"
BoldON="\033[1m"
BoldOFF="\033[22m"
NC="\033[0m" # No Color
Bold=$(tput smso)
#Normal=$(tput sgr0)
Normal=$(tput rmso)
export PS1="[$Green\u@$Blue$(uname -n)]:$Normal\$PWD: [${Bold}${Red}\${ORACLE_SID}${Normal}] > "
Thanks for your help and time.
 
Old 03-27-2012, 06:30 PM   #9
lithos
Senior Member
 
Registered: Jan 2010
Location: SI : 45.9531, 15.4894
Distribution: CentOS, OpenNA/Trustix, testing desktop openSuse 12.1 /Cinnamon/KDE4.8
Posts: 1,144

Rep: Reputation: 217Reputation: 217Reputation: 217
Have you exited the shell and reconnect/relogin ?

Are you maybe looking at this guide here ?

Last edited by lithos; 03-27-2012 at 06:32 PM.
 
1 members found this post helpful.
Old 03-27-2012, 06:32 PM   #10
saeedamer
LQ Newbie
 
Registered: Feb 2011
Posts: 25

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by lithos View Post
I would try yours like this:
Code:
add 
NORMALE=$(tput rmso)

export PS1="[$Green\u@$Blue \H]:$Normal \w: [${Bold}${Red}\${ORACLE_SID} $Normal $NORMALE] > "
It's pretty close to working I think, just not exactly what you want.
Thank you again - what is the fix for UP arrow behavior? It takes me to upper line (while still on unix prompt) if the previous command issued was longer one (does not fit on one line)? I hope you understand what I am trying to say :-(
 
Old 03-27-2012, 06:34 PM   #11
lithos
Senior Member
 
Registered: Jan 2010
Location: SI : 45.9531, 15.4894
Distribution: CentOS, OpenNA/Trustix, testing desktop openSuse 12.1 /Cinnamon/KDE4.8
Posts: 1,144

Rep: Reputation: 217Reputation: 217Reputation: 217
Huh,

I understand you now, but I'm sorry I don't have answer.
 
Old 03-27-2012, 06:34 PM   #12
saeedamer
LQ Newbie
 
Registered: Feb 2011
Posts: 25

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by lithos View Post
Have you exited the shell and reconnect/relogin ?

Are you maybe looking at this guide here ?
thanks for the URL - it is great. Now the color part is OK, it is the UP arrow thing that is bothering me now. Any ideas?
 
Old 03-27-2012, 06:36 PM   #13
lithos
Senior Member
 
Registered: Jan 2010
Location: SI : 45.9531, 15.4894
Distribution: CentOS, OpenNA/Trustix, testing desktop openSuse 12.1 /Cinnamon/KDE4.8
Posts: 1,144

Rep: Reputation: 217Reputation: 217Reputation: 217
Quote:
Originally Posted by saeedamer View Post

I tried your provided code and "(\[\e[33;1;44m\]$WINDOW\[\e[0m\]) " only displays "()". Looks like $WINDOW is not defined.
Yes, WINDOW is a variable set by Screen.
 
Old 03-27-2012, 06:37 PM   #14
saeedamer
LQ Newbie
 
Registered: Feb 2011
Posts: 25

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by lithos View Post
Huh,

I understand you now, but I'm sorry I don't have answer.
oh :-(
 
Old 03-27-2012, 06:44 PM   #15
lithos
Senior Member
 
Registered: Jan 2010
Location: SI : 45.9531, 15.4894
Distribution: CentOS, OpenNA/Trustix, testing desktop openSuse 12.1 /Cinnamon/KDE4.8
Posts: 1,144

Rep: Reputation: 217Reputation: 217Reputation: 217
I tried to look at some solutions,
like here (at the bottom)
Quote:
I had the same issue, and I don't think the problem has to do with the TERM variable. In fact, I tried changing it to "ansi" myself, and emacs got all screwed up.

You didn't put the value of PS1 in your original post, so I can only assume you're having the same issues I was, which was failing to mark the ANSI escape sequences as non-printing characters.

Before I had the following value for PS1:

'\e[0;34m\h:\w [\!]\$\e[0m '

which gave me a nice blue prompt of the following form

hostname:working-directory [command-number]$

However, I had the same line-wrapping problem you did. The fix was to insert \[ and \] around the ANSI escapes so that the shell knows not to include them in the line wrapping calculation. This results in the following value for PS1:

'\[\e[0;34m\]\h:\w [\!]\$\[\e[m\] '
then here

and here

I hope it helps.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
startx command in FC7 reverts me back to the command prompt sriram87 Linux - Newbie 5 01-03-2008 11:18 PM
changing prompt colors? microsoft/linux Debian 2 05-29-2005 04:22 PM
tcsh prompt with colors TroelsSmit Linux - Newbie 2 12-20-2004 07:55 AM
Key stroke/command to shut down x and go into the command prompt screen? Fear58 Linux - General 1 07-14-2004 07:14 PM
bash prompt colors emetib Linux - Software 3 06-14-2003 05:35 PM

LinuxQuestions.org > Forums > Enterprise Linux Forums > Linux - Enterprise

All times are GMT -5. The time now is 11:11 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