Tell me more ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

How can I set my prompt to be colourized in 256 colours? I am looking for an equivalent to the bash prompt:

  local DEFAULT="\[\033[0;39m\]"
  local ROOK="\[\033[38;5;24m\]"
  PS1="${ROOK}\$${DEFAULT} "
share|improve this question
1  
Shame on anyone who stared but not upvoted! – phunehehe Nov 25 '11 at 12:20
export PS1='%{[38;5;24m%};%{[0m%} ' is exactly what I wanted. – Sardathrion Nov 25 '11 at 12:32
1  

1 Answer

up vote 6 down vote accepted

First, ensure that your terminal supports 256 colors, which I suppose you already have. Second, use a PS1 variable with the correct code, for example:

export PS1='%{^[[01;38;05;214;48;05;123m%}%m%{^[[0m%} '

This will give you a prompt with the host name in bold, with a foreground color of 214 and a background color of 123.

Note that the ^[ is "entered" by typing Ctrl+v and Ctrl+[. See this excellent article "That 256 Color Thing" for the whole list of attributes.

share|improve this answer
Yes, I am using urxvt 256 colour enable terminal. – Sardathrion Nov 25 '11 at 12:31
How can I verify if my terminal supports 256 colors? For example, does gnome-terminal (Ubuntu) support 256 colors? – user815423426 Mar 31 at 17:39
Use this script (full article frexx.de/xterm-256-notes). gnome-terminal does support 256 colors. – phunehehe Apr 1 at 4:11

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.