LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   underlined text in PS1 variable? (https://www.linuxquestions.org/questions/linux-newbie-8/underlined-text-in-ps1-variable-801376/)

clifford227 04-11-2010 11:54 AM

underlined text in PS1 variable?
 
hi,

I want to underline my user & hostname in the PS1 variable, but I cant seem to do it.

I know that my Xterm can underline text normally, because when I pass Xterm the '+nul' option, then do this:

Code:

tput smul; echo underlined text; tput sgr0
it underlines. I just cant seem to get it to work for my PS1 variable, although its quite possible Im doing it incorrectly. has anyone managed to do this, is it possible?

here is my PS1 variable:

Code:

PS1='u @\h[\033[0m\]\[\e[m\]\[\033[1;33m\]\w \[\033[0m\]# '

IW2B 04-11-2010 02:14 PM

Hi,

Try

Code:

PS1='\[\033[0m\]\[\033[4;33m\] \u@\h \[\033[0m\]\w# '
Underline is defined by the 4 in the above example.

Or you can try doing the following. First define a few variables:

Code:

BLACK=$(tput setaf 0)
RED=$(tput setaf 1)
GREEN=$(tput setaf 2)
YELLOW=$(tput setaf 3)
BLUE=$(tput setaf 4)
MAGENTA=$(tput setaf 5)
CYAN=$(tput setaf 6)
WHITE=$(tput setaf 7)
BRIGHT=$(tput bold)
NORMAL=$(tput sgr0)
BLINK=$(tput blink)
REVERSE=$(tput smso)
UNDERLINE=$(tput smul)

Then use these variables in your PS1 setting:

Code:

PS1="${BRIGHT}${UNDERLINE}${RED}\u@\h${WHITE}${NORMAL}$ ${PWD}$ "
I just tried this on Fedora and Mac OSX

Ian

clifford227 04-14-2010 12:20 PM

thanks Ian, that looks a far eaier way to do it.


All times are GMT -5. The time now is 09:07 AM.