I want to make my hostname in my terminal orange. How do I do that?
3 Answers
Running the following code in your terminal should tell you whether your terminal supports 256 colors.
for COLOR in {0..255}
do
for STYLE in "38;5"
do
TAG="\033[${STYLE};${COLOR}m"
STR="${STYLE};${COLOR}"
echo -ne "${TAG}${STR}${NONE} "
done
echo
done
it also shows you the code for each color in the form 38;5;x
where x
is the code for one of the 256 available colors.
Also, note that changing the "38;5"
to "48;5"
will show you the background color equivalent. You can then use any colors you like to make up the prompt as previously mentioned.

- 9,608
- 6
- 34
- 56

- 13,172
- 10
- 68
- 94
-
4What is the value of `${NONE}`? – Dave Mar 22 '19 at 19:28
First off, I'm not sure what terminal you're using or if it will even support the color orange. Mine supports the following: Red, Blue, Green, Cyan, Yellow, Magenta, Black & White. And here's how I get colors in my terminal:
You need to first load the colors using autoload
. I use the following to load the colors and assign them to meaningful names
#load colors
autoload colors && colors
for COLOR in RED GREEN YELLOW BLUE MAGENTA CYAN BLACK WHITE; do
eval $COLOR='%{$fg_no_bold[${(L)COLOR}]%}' #wrap colours between %{ %} to avoid weird gaps in autocomplete
eval BOLD_$COLOR='%{$fg_bold[${(L)COLOR}]%}'
done
eval RESET='%{$reset_color%}'
You can set the hostname in your prompt using the %m
string. So to set, say a red hostname, you'd do
${RED}%m${WHITE}\>
which will print something like bneil.so>

- 278,309
- 50
- 514
- 539

- 41,765
- 7
- 81
- 98
-
This is a great snippet @yoda. Do you know if there is a way to 1) Know what colors are loaded in autoload colors && colors? 2) Know what colors are supported by your terminal? – Amelio Vazquez-Reina Aug 26 '11 at 15:09
-
3These are the colors that are loaded by `autoload`. That little loop merely renames them to more intuitive color names (e.g., `RED` instead of `fg_no_bold_RED` or something like that). If you're running Mac OS X 10.6 and below, the default Terminal.app will support only 16 colors. You can download `iterm2` for Mac which is a great terminal and supports 256 colors. With OS X 10.7, I think Terminal.app supports 256 colors (although I can't verify as I haven't upgraded). You can also use [this handy script](http://www.vim.org/scripts/script.php?script_id=1349) to see how many colors it supports. – abcd Aug 26 '11 at 23:52
-
@yoda, I added the percent wrapping to the RESET as well. It has the same "weird gap" issue for me otherwise. – Matthew Flaschen Oct 10 '13 at 08:49
-
When I try to use this first snippet I get the error: `command not found: autocomplete` – jarrodwhitley Mar 25 '22 at 19:43