zsh

What Colors Are Supported by Zsh?

Zsh is a powerful command-line shell that helps you customize your shell environment according to your needs. It has become a popular choice among developers and system administrator since it offers several cool features that can enhance your command line shell and provides you with an appealing interface.

If you are wondering how many colors are supported by Zsh, you are at the right place. Here, you will find a detailed guide about the colors used in Zsh.

What Colors Are Supported by Zsh?

When you install Zsh and run the command-line interface for the first time, you will see a simple prompt with grey text color and black background.

However, you will be glad to know that Zsh has several color options that can change your Zsh prompt look.

There are almost 16 color options in Zsh divided into two groups.

  • Basic Colors
  • Bright Colors

What are the Basic Colors in Zsh?

In Zsh, the basic colors are the types of colors that are not created by mixing other colors; there are almost 8 basic colors you will find in Zsh, which are as follows:

  • Red
  • Black
  • Green
  • Yellow
  • Blue
  • Cyan
  • White
  • Magenta

What are Bright Colors?

Bright colors are the type of colors with high saturation and lightness; they are more enhanced versions of basic colors and could be more prominent and eye-catching compared to other colors. There are almost 8 bright colors in Zsh, which are:

  1. Bold Red
  2. Bold Black
  3. Bold Green
  4. Bold Yellow
  5. Bold Blue
  6. Bold Cyan
  7. Bold White
  8. Bold Magenta

Other than that, Zsh also supports several other attributes, which are:

  1. Bold: A bold font.
  2. Background: The color of the background.
  3. Foreground: The color of the text.
  4. Reverse: The foreground and background colors are swapped.
  5. Underline An underlined font.

How to Test Basic Colors in Zsh?

It is pretty simple to test the colors in Zsh, which can be done by executing the following command in the terminal.

print -P '%B%F{cyan}lin%F{red}ux%F{blue}hint%f%b'

The above code will display the colored text linuxhint in different colors where %B and %b sequences are used to turn on and off the bold text, %F will see the foreground color to cyan, red and blue, while %f will reset the color back to the Zsh default.

For setting the prompt color for your Zsh, you can use the following code:

PROMPT='%F{blue}%n%f@%F{magenta}%m%f %F{red}%B%~%b%f %# 'RPROMPT='[%F{cyan}%?%f]'

The above code is an example of a two-sided prompt with colors.

To use colors from both the 16-255 range and the 24-bit true color spectrum, you have two options.

For colors in the 16-255 range, you can utilize the assigned numbers ranging from 0 to 255 to achieve your desired color.

ROMPT='%F{3}%n%f@%F{5}%m%f %F{4}%B%~%b%f %# '
RPROMPT='[%F{2}%?%f]'

Doing the above command will apply the color setting on the current command window; the settings will be removed once you close the terminal and open it again.

How to Set the Color of Prompt in Zsh?

To set the color of the prompt in your Zsh, you must open the .zshrc configuration file and add the following line:

autoload -U colors && colors
PS1="%{$fg[blue]%}%n%{$reset_color%}@%{$fg[red]%}%m %{$fg[black]%}%~ %{$reset_c$

Save the file using Ctrl+X, and reload the changes using the following command:

source ~/.zshrc

This will change the prompt color as soon as you load the changes.

Conclusion

Zsh is a powerful command-line shell that offers several colors to change the look of your command prompt. There are almost 16 colors that Zsh supports, which are divided into two categories; basic and bright. The basic colors are normal, while bright colors are a more enhanced version of basic colors. This guide has provided a detailed guide about the colors supported by Zsh and how you can change them to customize the look of your command prompt.

About the author

Awais Khan

I'm an Engineer and an academic researcher by profession. My interest for Raspberry Pi, embedded systems and blogging has brought me here to share my knowledge with others.