It would be cool if the bash prompt can be used a a mini task bar.

Can the bash prompt (PS1) show the names of the jobs listed in the jobs command?

  • You can put anything you like in PS1, including $(jobs|Filter), where Filter massages the output into whatever format you want. To get everything on one line use echo $($(jobs|Filter)). You can of course add all the other characters you would normally use in PS1, but you must use single quotes when assigning it, to make sure that the embedded command is expanded when the prompt is issued, rather than when the variable is set. – AFH Jan 27 '16 at 2:39

AFH in the comment gives you the builing blocks. Here is one example how to get the quoting correct.

as "name of the job", I choose the command name of the job (the first word after "Running"):

PS1='$(echo $(jobs | awk '\''/Running/{print "[" $3 "]"}'\''))$ '

And when trying that out with two background commands, and just typing "enter" a few times to see the prompt changing:

$ sleep 4 & sleep 2 &
[1] 7222
[2] 7223
[sleep] [sleep]$ 
[sleep] [sleep]$ 
[2]+  Done                    sleep 2
[1]+  Done                    sleep 4

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.