Question

This article's code does not work for me. I have pasted all its code to my .zshrc.

I have the following in my .zshrc

RPROMPT='%{\[0;33m%}%1v%{\[0m%}'

It should indicate whether you have jobs or not. However, it does not do that for me.

I would like to get an X to the right prompt to indicate that you have a job running.

How can you have a right prompt which shows X if you have more than one jobs in Zsh?

Was it helpful?

Solution

The code you're using won't work because it's trying to use the $psvar variable, which you haven't set. Probably that article mentioned it somewhere else.

Anyway, to display the number of jobs in the RPROMPT, use

$> RPROMPT="%j Job(s)"

To have it display an 'X' if you have at least one job running, use

$> RPROMPT="%1(j.X.)"

Look under the PROMPT section of the zshmisc manpage, or take a link: http://www.manpagez.com/man/1/zshmisc/ . It explains all the expansion sequences that you can use to display information in your prompt.

OTHER TIPS

It looks like you're missing extra left brackets from from your ANSI escape sequences, plus I don't think \[ is doing what you expect.

Here's what you want:

RPROMPT="%(1j.%{^[[33m%} X%{^[[0m%}.)"

However, you may find it more useful for the prompt to show how many jobs are in the background:

RPROMPT="%(1j.%{^[[33m%} (%j jobs)%{^[[0m%}.)"

Note: Those ^[ above are literal escape characters — e.g., 0x1B. On the command line (or in Vim's insert mode if you're using Vim to edit your .zshrc) type Control-V then Control-[ to insert an escape character.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top