我希望根据某些命令的输出来更改提示。并根据命令结果添加颜色。
示例:
运行命令:
cphaprob stat | grep local | awk '{ print $NF }'`
(这只会显示最后一个字。
现在,如果结果是“ attention”,我希望提示是:
PS1='[\t][\u@\h]\[\e[0;92m\][attention]\[\e[0m\]# '
因此“注意”一词将变为绿色。
但是,如果单词是“ down”,则我希望提示符使用不同的颜色:
PS1='[\t][\u@\h]\[\e[4;91m\][Down]\[\e[0m\]# '
我希望更改是“即时”的,这意味着在每个新行上(按Enter),我希望根据结果来更新提示。
如果可能,应通过.bashrc将其永久化。
有关如何使其工作的任何想法?
这对我有效(使用bash 4.2.37):
PS1='[\t][\u@\h][$(i=$(cphaprob stat|grep local|awk "{print \$NF}")
u=0
case $i in
(Active|attention) c=92;;
(Down|Error) u=4; c=91;;
(Standby) c=93;;
(Ready) c=94;;
(*) c=95 ;;
esac
printf "\033[%s;%sm%s\033[0m" $u $c $i
)]# '
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句