zsh ansi 颜色代码如何工作? [英] How do zsh ansi colour codes work?

查看:43
本文介绍了zsh ansi 颜色代码如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将我的终端中的主机名设为橙色.我该怎么做?

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

推荐答案

首先,我不确定您使用的是什么终端,或者它是否支持橙色.我的支持以下内容:红色、蓝色、绿色、青色、黄色、洋红色、黑色和黑色白色的.这是我在终端中获取颜色的方法:

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:

您需要首先使用 autoload 加载颜色.我使用以下内容加载颜色并将它们分配给有意义的名称

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%}'

您可以使用 %m 字符串在提示中设置主机名.所以要设置,说一个红色的主机名,你会做

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}\>

将打印类似 bneil.so>

这篇关于zsh ansi 颜色代码如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆