MacOS – Install Monokai Theme on Terminal with prompt colors, etc.

bashcolormacossublimetextterminal

I already have a Monokai theme installed in Terminal, as so:

enter image description here

I was wondering how I could get the rest of the Monokai (as Sublime uses) into Terminal? Like, making the prompt (Gamma@~) colored, etc.

Here is my current .bash_profile file:

export PATH=/usr/local/bin:$PATH
export CLICOLOR=1
export LSCOLORS=gxBxhxDxfxhxhxhxhxcxcx
export PS1="\u@\w $ "
alias ls='ls -G'

Thank you very much! I know this question is rather vague, but I cannot seem to find a PS1 color scheme that matches Monokai.

Best Answer

See this answer on the Unix & Linux SE. There are a number of additional colors that can be used in a 256 color terminal.

You can view the colors in Terminal, and see their codes, by running this bash script. (There is a also a color chart in the above linked post, or IMO a more readable chart here.)

#!/bin/bash

color=16;

while [ $color -lt 245 ]; do
    echo -e "$color: \\033[38;5;${color}mhello\\033[48;5;${color}mworld\\033[0m"
    ((color++));
done

Once you determine the colors you want, and have the color codes, you can use them in a PS1 prompt like shown below.

48;5;# where # is the color number you want, sets the background color.

38;5;# again # replaced with the color number, sets the foreground color.

In my case I wanted the default background that Terminal set when it was launched, and I use 0 to note this. (You can also see that toward the end of the sequence \[\e[0m\] - same idea, using 0 to reset everything to the default.)

export PS1='\[\e[0;38;5;166m\]\u@\H\[\e[0m\] \w $ '

The below screenshot shows my original, default prompt, and then how it looks when I sourced .bash_profile after defining PS1:

enter image description here