labbook

show the number of jobs in your Fish shell

Once in a while I like to mess around with the Fish shell. Until recently, I used zsh with a custom starship prompt. I like my current setup with fish, but I really miss being able to see the number of suspended jobs in the prompt, like I had set up with starship.

To add this little bit of information to my fish prompt, I wrote the following snippet into the end of my fish_prompt function.1

# jobs
set_color $fish_color_user # Or any other color you like.
set -l jobs (jobs | wc -l)
if test $jobs -gt 0 # Only show when there are suspended jobs.
    echo -n "{$jobs} "
end
set_color normal

While in a directory with version control and a suspended job, the prompt2 will look something like this (no colors shown):

~/s/dwangschematiek (main|✔) {1} $
1

Most likely, you will find this file at ~/.config/fish/functions/fish_prompt.fish. Otherwise, check the relevant fish docs.

2

In case you’re curious, here’s a snapshot of my current fish prompt. It is basically the ‘Informative Vcs’ prompt with my little jobs module glued into it.