3

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?

Jens
  • 69,818
  • 15
  • 125
  • 179
Léo Léopold Hertz 준영
  • 134,464
  • 179
  • 445
  • 697

2 Answers2

5

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
  • 96,888
  • 11
  • 64
  • 71
  • 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. – Léo Léopold Hertz 준영 May 08 '09 at 08:13
1

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
  • 30,702
  • 30
  • 134
  • 179