开发者

What does ${#${(S%%)string//(\%([KF1]|)\{*\}|\%[Bbkf])}} mean

开发者 https://www.devze.com 2022-12-20 01:05 出处:网络
I found this in the adam2 zsh prompt, and I have no idea what it means.Apparently it counts the length of the \"string\", but how it does that is beyond me.

I found this in the adam2 zsh prompt, and I have no idea what it means. Apparently it counts the length of the "string", but how it does that is beyond me.

${#${(S%%)string//(\%([K开发者_JAVA百科F1]|)\{*\}|\%[Bbkf])}}


Your pattern counts the length of the string after stripping out some ANSI-style character formatting.

Approximately:

  • ${# } - length

  • ${ } - nested

  • (S%%) - search substrings starting from the end

  • // - substitute globally (in this case delete, since there's no slash later)

  • ( ) - capture group

  • \% - literal percent sign

  • [KF1] - character list: K=begin background color, F=begin foreground color

  • [Bbkf] - character list: B=begin bold, b=end bold, k=end background, f=end foreground

And then I get lost.


I googled "zsh prompt regex", and found this. It says $# counts the length of the contents. That link also has more info than the zsh user's guide I found.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号