Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: can i have jobs in my prompt?



Note: I'm CCing this reply to zsh-users, as the answer is likely to be
of general interest.


Matthias Kopfermann wrote:
>i forget how many jobs are running, especially if they are in the background.
>what would you do here?
>
>-f4-7)-%{`builtin jobs`%}-

Don't use %{%}.  They are used to indicate a sequence that doesn't move
the cursor, such as a colour escape sequence.  Also, $() is recommended
over ``, but in any case jobs doesn't work in a subshell.  A possible
approach would be to put something in precmd (a function run before each
prompt) like this:

function precmd {
  if jobs % >& /dev/null; then
    psvar=("*")
  else
    psvar=("")
  fi
}

And then put "%1v" in your prompt, for example:

PROMPT="%1v> "

and this will put a * in your prompt if there are any background jobs.
You can substitute any other sequence.

I think I might start using this myself.

-zefram



Messages sorted by: Reverse Date, Date, Thread, Author