bash_kernel icon indicating copy to clipboard operation
bash_kernel copied to clipboard

Colour cells red on non-zero exit code

Open bitdivine opened this issue 4 years ago • 1 comments

In bash, a non-zero exit code indicates that something has gone wrong.

When doing deployments, it is important to know if something has gone awry.

I have set up my bash terminal so that the prompt turns red if the last command exited with a non-zero exit code, or green otherwise.

It would be cool if the bash_kernel could do something similar. Perhaps the jupyter cell could be tinted red or green; I don't know whether there is an API for that.

Alternative: I note that PROMPT_COMMAND works in the bash kernel, so this will print the exit code after each cell has exited:

function __prompt_command() { echo EXIT $? ; }
export PROMPT_COMMAND=__prompt_command
> x=7
EXIT 0
> false
EXIT 1

bitdivine avatar Feb 11 '21 13:02 bitdivine

It should correctly treat a non-zero exit as an error, so it will stop there if you have done 'run all', or executed it from the command line with something like nbconvert. But like bash itself, by default there's no visual indication of this, because it's normally up to the commands you run to give an error message. Jupyter doesn't really have a kernel API for colouring cells or anything like that - the output below a cell is the main visual indication a kernel can give.

If you want to add your PROMPT_COMMAND setting as an idea in the README for people to set themselves if they want it, I'd be happy with that.

takluyver avatar Feb 11 '21 14:02 takluyver