Skip to main content
Post Undeleted by Stephen Harris
Total rewrite of answer!
Source Link
Stephen Harris
  • 49.4k
  • 7
  • 115
  • 138

A combination ofBy default if you just set PS1="...." then the two might workstuff inside the quotes is evaluated at the time you set it.

However if you enclose it inside ' instead then it's evaluated at display time. And it doesn't cause a subshell for $(jobs).

e.g.

% trap$ 'PS1="PS1=' > $(jobs) %> "'$ DEBUG' % $ sleep 1000 & [1] 7541  [1] + Running 6991 sleep 1000 & $ sleep 1000 & %[2] echo7543 [2] + Running sleep 1000 & [1] - Running sleep 1000 & $ kill %1 [1] - Terminated  sleep 1000 & [2] + Running sleep 1000 & %$ kill %2 [2] + Terminated sleep 1000 & $ 

The downside of this is that the prompt doesn't get set immediately; we needed the intermediate command (echo) in this case to cause the DEBUG trap to fire. But the job output appears in PS1.

You might want to try the KEYBD trap; this gets called for each keypress so may be a little "heavy", but it works better; now you just need to press RETURN to get an updated prompt.

(The above tested on ksh93This test done on Debian Jessie, with ksh93 but should work on anyall ksh93 installs)variants; I don't have any ksh88 to test with.)

A combination of the two might work...

% trap 'PS1=" $(jobs) % "' DEBUG % sleep 1000 & [1] 6991 % echo [1] + Running sleep 1000 & % 

The downside of this is that the prompt doesn't get set immediately; we needed the intermediate command (echo) in this case to cause the DEBUG trap to fire. But the job output appears in PS1.

You might want to try the KEYBD trap; this gets called for each keypress so may be a little "heavy", but it works better; now you just need to press RETURN to get an updated prompt.

(The above tested on ksh93 on Debian Jessie, but should work on any ksh93 installs).

By default if you just set PS1="...." then the stuff inside the quotes is evaluated at the time you set it.

However if you enclose it inside ' instead then it's evaluated at display time. And it doesn't cause a subshell for $(jobs).

e.g.

$ PS1=' > $(jobs) > $ '  $ sleep 1000 & [1] 7541  [1] + Running  sleep 1000 & $ sleep 1000 & [2] 7543 [2] + Running sleep 1000 & [1] - Running sleep 1000 & $ kill %1 [1] - Terminated  sleep 1000 & [2] + Running sleep 1000 & $ kill %2 [2] + Terminated sleep 1000 & $ 

(This test done on Debian Jessie with ksh93 but should work on all ksh93 variants; I don't have any ksh88 to test with.)

Post Deleted by Stephen Harris
Source Link
Stephen Harris
  • 49.4k
  • 7
  • 115
  • 138

A combination of the two might work...

% trap 'PS1=" $(jobs) % "' DEBUG % sleep 1000 & [1] 6991 % echo [1] + Running sleep 1000 & % 

The downside of this is that the prompt doesn't get set immediately; we needed the intermediate command (echo) in this case to cause the DEBUG trap to fire. But the job output appears in PS1.

You might want to try the KEYBD trap; this gets called for each keypress so may be a little "heavy", but it works better; now you just need to press RETURN to get an updated prompt.

(The above tested on ksh93 on Debian Jessie, but should work on any ksh93 installs).