justjanne / powerline-go

A beautiful and useful low-latency prompt for your shell, written in go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Example setup for zsh job count doesn't work.

Magicrafter13 opened this issue · comments

Using the example setup in README.md for the jobs module, does not work - as far as I can tell, due to how sub-shells work.

Just use the script in the readme. But for a setup, I removed my zsh config, so I could get this screenshot to show what I'll be talking about below.

Screenshot_20211104_183241

Disclaimer that before tonight I did not know about zsh's prompt expansion, or this syntax: ${()}. But because of how strange it looks I knew it didn't come out of nowhere, so I looked into it, and eventually figured out, more or less, what it is trying to do. And after looking at some other examples online, all I did was add a hyphen after the (%):, and viola, we get the number.

Unfortunately, as you can see in the screenshot, simply adding the hyphen still doesn't make the number appear in powerline-go's output, and I don't think it can - at least, with this syntax: ${${(%):-%j}:-0} - with PS1=$(powerline-go ...) since it is being executed in a sub-shell. Now, as for why echo $(echo $?)) works while echo $(echo ${${(%):-%j}:-0}) does not, I can't say.

The reason I'm making this an issue instead of a pull request, is because I'm not familiar enough with the project to know what approach you would prefer to fix this. I've already demonstrated one approach in my screenshot, where the job number could be saved to a variable, and then given to -jobs. But perhaps there is a cleaner solution. Also not sure if ${${(%):%j}:-0} never worked, and it just slipped by due to not many people using the jobs module, or maybe it worked in earlier versions of zsh?

A more readable way to do it would be $(print -P '%j') but this is probably slower than ${${(%):-%j}:-0}. Depends on what kind of balance you want to strike between beginner-friendly, and objectively-better :p.

Edit: I also just tried ${(%):-%j} and still get a number (even if there are zero jobs) so I don't think the :-0 is necessary.

  • OS: Manjaro
  • Architecture: Intel
  • Shell: zsh