tags:

views:

78

answers:

3

I know the article which code does not work for me. I have pasted all its codes to my .zshrc.

I have the following code 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 a X to the right prompt to indicate that you have a job open.

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

A: 

Check here for an example, under the "Background jobs".

Chris Simmons
I sourced the codes in the site to my .zshrc. I did not get the indication of jobs to the right prompt.
Masi
Sorry to hear that - I would have tried it out myself but I don't have zsh kicking around.
Chris Simmons
A: 

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.

a paid nerd
+1  A: 

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.

sykora
Thank you for your answer! -- I have now the following in my .zshrc: RPROMPT=$(echo '%{\033[32m%}%~ %1(j.%j.)'). Is there any way to write the same shorter? I tried without echo unsuccessfully.
Masi