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:
- Bold Red
- Bold Black
- Bold Green
- Bold Yellow
- Bold Blue
- Bold Cyan
- Bold White
- Bold Magenta
Other than that, Zsh also supports several other attributes, which are:
- Bold: A bold font.
- Background: The color of the background.
- Foreground: The color of the text.
- Reverse: The foreground and background colors are swapped.
- 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.
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:
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.
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:
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:
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.