Search code examples
zshzshrczsh-alias

Use of nested ternary expression in .zshrc prompt configuration


what is wrong with my RPS1 expression

RPS1='%(t.[Ding!].%(t30.[Dong!].[%T]))'

Explanation:

I want to get [Ding!] if it is 11am, [Dong!] if it is 11:30am and if both is not true just normal time like [11:33]. But what is wrong?

Tanks


Solution

  • The numerical argument to the ternary expression needs to be either just before or just after the opening parenthesis (See the section on Conditional Substrings in Prompts in the ZSH manual) . So either of those will work:

    RPS1='%(t.[Ding!].%30(t.[Dong!].[%T]))'
    RPS1='%(t.[Ding!].%(30t.[Dong!].[%T]))'