0

I am creating a custom zsh prompt based on this zsh theme https://github.com/robbyrussell/oh-my-zsh/blob/master/themes/jonathan.zsh-theme but I'm having difficulty deciphering this line of code...

local promptsize=${#${(%):---(%n@%m:%l)---()--}}

Could someone please explain it?

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
Paul Hale
  • 307
  • 4
  • 14
  • 1
    [zsh Manual - 13 Prompt Expansion](http://zsh.sourceforge.net/Doc/Release/Prompt-Expansion.html) (hint: `promptsize` is simply a variable holding the prompt size, e.g. `${#.....}`, the `${(%....}` is the prompt from which the length is taken) Personally, I like single-line prompts, try `PS1="%F{243}%T %F{27}%m:%~>%f "` for user and `PS1="%F{243}%T %F{27}%m:%F{1}%~ %F{27}#%f "` for root. – David C. Rankin Jul 06 '19 at 00:32
  • Wouldn't be `${#${(%)PS1}}` be an easier way to get the length of the (expanded) prompt? – user1934428 Jul 08 '19 at 07:15

1 Answers1

0

The outer ${# ... } returns the length of its (inner) argument, ${(%)....}. The % modifier causes prompt expansion of what follows. Hence, :---(%n@%m:%l)---()-- is interpreted as prompt string, and promptsize is set to the size of this prompt in expanded form.

user1934428
  • 19,864
  • 7
  • 42
  • 87