Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example setup for zsh job count doesn't work. #334

Open
Magicrafter13 opened this issue Nov 5, 2021 · 0 comments
Open

Example setup for zsh job count doesn't work. #334

Magicrafter13 opened this issue Nov 5, 2021 · 0 comments
Labels

Comments

@Magicrafter13
Copy link

Magicrafter13 commented Nov 5, 2021

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant