takluyver / bash_kernel

A bash kernel for IPython
BSD 3-Clause "New" or "Revised" License
702 stars 144 forks source link

`]777;preexec\` before and `: 1` after the output #147

Open willianrampazzo opened 5 months ago

willianrampazzo commented 5 months ago

I have just installed bash_kernel for some testing and all my cell outputs have ]777;preexec\ before and : 1 after the output. The : 1 output is show on a red line. Is it expected?

Example:

]777;preexec\ls: cannot access 'foo': No such file or directory
: 1

image

Software versions:

$ bash --version
GNU bash, version 5.2.26(1)-release (x86_64-redhat-linux-gnu)
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
$ jupyter --version
Selected Jupyter core packages...
IPython          : 8.24.0
ipykernel        : 6.29.4
ipywidgets       : not installed
jupyter_client   : 8.6.1
jupyter_core     : 5.7.2
jupyter_server   : 2.14.0
jupyterlab       : 4.2.0
nbclient         : 0.10.0
nbconvert        : 7.16.4
nbformat         : 5.10.4
notebook         : 7.2.0
qtconsole        : not installed
traitlets        : 5.14.3
takluyver commented 5 months ago

It's not expected - it's probably something to do with your local config of bash.

This script from pexpect tries to reset bash to a predictable state for bash_kernel & similar programs to use, while still picking up things you probably want like custom aliases:

https://github.com/pexpect/pexpect/blob/master/pexpect/bashrc.sh

But bash is pretty flexible, so it's probably missing something.

willianrampazzo commented 5 months ago

Thanks for the quick reply!

I've spawned a fresh Fedora 40 virtual machine and tested the bash kernel. The output is still the same. The script you mentioned did not help.

I'll investigate deeper when I have some spare time.

takluyver commented 5 months ago

Ah, I think it's something Fedora is setting in /etc/bash_profile.d/vte.sh. We/Pexpect might want to reset PS0 as well as PS1, and/or unset VTE_VERSION so the vte (GTK terminal library) customisations don't get used.

The script you mentioned did not help.

Sorry, I wasn't very clear: bash_kernel already uses that script to set up bash. I wouldn't expect running it again to fix it.

willianrampazzo commented 5 months ago

That was it!

Without investigating the cause, I've just removed the /etc/profile.d/vte.sh file and commands that succeed now show correctly using the bash kernel. Commands that return anything other than 0 still show the return code with a red line at the bottom of the output.

Feel free to close this issue as a "user-side problem" or use it to track the change you suggested in the previous comment.

Thanks again for your quick replies and help!

willianrampazzo commented 5 months ago

FYI, as a workaround on my side, I added "VTE_VERSION": "" to https://github.com/takluyver/bash_kernel/blob/master/bash_kernel/install.py#L16, and it did the trick.