How do zsh ansi colour codes work?

前端 未结 4 725
后悔当初
后悔当初 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:44

    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>

提交回复
热议问题