zsh 的一个问题

2016-02-20 17:07:40 +08:00
 hongfeiyu

设置"%(!.%{%F{yellow}%}.)$USER@%m"里的(!.%{%F{yellow}%}.)
是什么意思啊
???

1877 次点击
所在节点    程序员
4 条回复
neoblackcap
2016-02-20 23:06:54 +08:00
感觉是一个字符串格式化的意思,应该是以某种格式,加字体颜色为黄色输出的意思。
hongfeiyu
2016-02-20 23:49:43 +08:00
@neoblackcap 我猜是如果是 root 用户的话就显示闪电的标志。。。
wittyfox
2016-02-21 00:10:15 +08:00
来自官方 Manual 的解释

%(x.true-text.false-text)

Specifies a ternary expression. The character following the x is arbitrary; the same character is used to separate the text for the ‘ true ’ result from that for the ‘ false ’ result. This separator may not appear in the true-text, except as part of a %-escape sequence. A ‘)’ may appear in the false-text as ‘%)’. true-text and false-text may both contain arbitrarily-nested escape sequences, including further ternary expressions.

The left parenthesis may be preceded or followed by a positive integer n, which defaults to zero. A negative integer will be multiplied by -1, except as noted below for ‘ l ’. The test character x may be any of the following:

!
True if the shell is running with privileges.

意思就是说,如果是 root 就用黄色。
hongfeiyu
2016-02-21 00:21:22 +08:00
@wittyfox O(∩_∩)O 谢谢,可以结贴了

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/257875

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX