我在 Bash 脚本中经常使用颜色(主要在 CentOS 上),但为了使它们的使用更方便,我最终将变量重新定义为颜色值:
local GRAY="\[\033[1;30m\]"
local LIGHT_GRAY="\[\033[0;37m\]"
local CYAN="\[\033[0;36m\]"
local LIGHT_CYAN="\[\033[1;36m\]"
local NO_COLOUR="\[\033[0m\]"
Run Code Online (Sandbox Code Playgroud)
或者也有tput:
bold=`tput bold`
normal=`tput sgr0`
whitef=`tput setaf 7`
greenf=`tput setaf 2`
redb=`tput setab 1`
Run Code Online (Sandbox Code Playgroud)
我已经搜索了/etc/rc.d/init.d目录,但没有找到任何与颜色定义相关的内容。
是否已经有了这样的定义?如果不是,我会将它们放入一个文件中/etc/rc.d/init.d,并将其包含在我的脚本中,有点像/etc/rc.d/init.d/functions
我最近从rxvt-unicode切换到st。这意味着我从$TERM=rxvt-unicode-256color到$TERM=st-256color.
我对切换很满意,并希望继续使用st. 但是,我注意到某些终端应用程序对新$TERM值不满意。例如,除非我“欺骗”它认为它是可识别的东西,emacs否则不会加载st全彩色支持。$TERM$TERM=xterm-256color
我的问题是:简单设置的风险是什么$TERM=xterm-256color?在我看来,重要的部分$TERM=*-256color是256color部分,而 的价值*似乎不那么重要。
如何在终端中显示颜色以处理十六进制颜色值?它对于主题化、XResources 等很有用。例如:
$ command '#FF0000'
// display a red square
Run Code Online (Sandbox Code Playgroud)
我在 manjaro 中使用 urxvt、i3wm。
我有以下代码。
bold=''
reset=$(echo -en '\033[0m')
black=$(echo -en '\e[1;30m')
magenta=$(echo -en '\033[00;35m')
blue=$(echo -en '\e[1;34m')
cyan=$(echo -en '\e[1;36m')
green=$(echo -en '\e[1;32m')
orange=$(echo -en '\e[1;33m')
purple=$(echo -en '\e[1;35m')
red=$(echo -en '\e[1;31m')
white=$(echo -en '\e[1;37m')
yellow=$(echo -en '\e[1;33m')
lime_yellow=$(echo -en '\e[1;33m')
power_blue=$(echo -en '\e[1;34m')
blink=$(echo -en '\e[1;31m')
reverse=$(echo -en '\e[1;31m')
underline=$(echo -en '\e[1;31m')
if [ -x /usr/bin/tput ] && tput setaf 1 &>/dev/null; then
echo "tput color is supported."
tput sgr0 # Reset colors
bold=$(tput bold)
reset=$(tput sgr0)
black=$(tput setaf 0)
magenta=$(tput setaf …Run Code Online (Sandbox Code Playgroud)