Cover image for Custom colors in oh-my-zsh themes

Custom colors in oh-my-zsh themes

yujinyuz profile image Yujin Updated on ・2 min read

Custom colors in oh-my-zsh themes

So, I was trying to configure my custom zsh theme. I wanted something minimal like displaying the current user, a shortened path and the git info of a directory (if there is).

After a few hours of tinkering, I pretty much got what I wanted but the only thing I didn't like was the colors available.

I wasn't sure which file to look for that contains the fg_bold and fg.

I did try doing a ripgrep: rg fg_bold hoping that I would find a list of available colors. But all I found were .zsh-theme files that were using a fixed set of colors. Magenta, green, blue, yellow, cyan were the ones I found.

Alt Text

I wasn't satisfied with the colors available and I did some trial and error by doing $fg_bold[orange], $fg[pink], etc. But I had no luck.

I did some google search about defining custom colors in zsh and it led me to this GitHub issue: https://github.com/ohmyzsh/ohmyzsh/issues/1101#issuecomment-5450278

It seems that oh-my-zsh uses Spectrum under the hood. The source code can be found under ~/.oh-my-zsh/lib/spectrum.zsh.

Upon checking the source code, I tried running spectrum_ls on my terminal and I was amazed by the output :asto

Alt Text

I can now use custom colors on my custom zsh theme via $FG[<0-255>] e.g. $FG[021]

So, that's it! I just wanted to share how I managed to define custom colors in my zsh setup.

I mainly use Python and Javascript so I did add a few customizations like displaying the node and python version of the current environment.

I made a minimal version of the theme I was working on for those who might be interested: https://github.com/yujinyuz/dotfiles/blob/master/zsh/themes/jpro-minimal.zsh-theme

Alt Text

You can check out the documentation on adding themes to oh-my-zsh: https://github.com/ohmyzsh/ohmyzsh/wiki/Customization#overriding-and-adding-themes

Thanks for reading! It was a great experience writing my first article here on dev.to after being a member for about 2 years now 😅

Posted on by:

yujinyuz profile



A Software Developer. A lazy one.


markdown guide

Nice! is there a way I can use this to costumize the Git coloring?


Are you talking about the ones in ~/.gitconfig ? I think you could use It


no I meant the theme colors used by oh-my-zsh when working on git stuff. but in the meantime I finally found the answers :) you can change that in the theme or in .zshrc with the following values (in my case of using powerlevel9k) and edit the color numbers(which are also using the spectrum color schemes):


That's awesome! Others might find this useful. Thanks for sharing that as well :)