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//(\%([KF1]|)\{*\}|\%[Bbkf])}}
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//(\%([KF1]|)\{*\}|\%[Bbkf])}}
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.
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.