Colored Prompt in KornShell

colorskshprompt

According to this StackOverflow post, it is possible have a colored prompt in KornShell. I have not been able to figure out how to do this. I am able to use color:

echo -e "\033[34mLinux\033[00m"

gives a blue "Linux" output, as does:

printf "\033[34mLinux\033[00m"

However, when I incorporate the escape codes into my PS1 prompt variable, they are not being escaped. What do I need to do to get a colored prompt? Besides being something of a sucker for eyecandy, I find that a colored prompt is useful when visually parsing output.

Best Answer

Just use a literal Esc character, entered with Ctrl-v,Esc (will be displayed as ^[ on the screen):

PS1="^[[34mLinux^[[00m"

Or use the output of the echo command you find out is working:

PS1="$(echo -e "\033[35mLinux\033[00m")"
Related Question