How do zsh ansi colour codes work?

前端 未结 4 719
后悔当初
后悔当初 2020-12-13 09:45

I want to make my hostname in my terminal orange. How do I do that?

4条回答
  •  情歌与酒
    2020-12-13 10:25

    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.

提交回复
热议问题