Update: providing patches for ipython as well.
I recently upgraded to 0.24 and explored the shell integration features. I was delighted with these features and thought it would be great within my nvim + jupyter console workflow. My current workflow requires a lot of cut+paste from jupyter console to a text file. I was able to hack jupyter console so it works well with the shell integration features. Now, when I run a command, I no longer have to select and then paste. I just get the entire output selected using shell integration and then paste it where I wanted. This required me to insert the escape codes at the right locations in the jupyter_console/ptshell.py file. Everything works like a charm now. I am the relevant patches below for others to try-
if [[ -e "$site_packages"/jupyter_console/ptshell.py ]]; then
echo "Patching $site_packages/jupyter_console/ptshell.py"
perl -0777 -pi -e "$(cat <<'_E_'
s{\Q
if PTK3:
text = await self.pt_cli.prompt_async(default=default)
\E}
{
def sys_write\(\):
import sys
sys.stdout.write\(u"\\u001b\\u005d133;A\\u001b\\u005c"\)
pre_run = sys_write
if PTK3:
text = await self.pt_cli.prompt_async(default=default, pre_run=pre_run)
}gsx
_E_
)" "$site_packages"/jupyter_console/ptshell.py
perl -0777 -pi -e "$(cat <<'_E_'
s{\Q
while self.client.iopub_channel.msg_ready():
sub_msg = self.client.iopub_channel.get_msg()
msg_type = sub_msg['header']['msg_type']
\E}
{
while self.client.iopub_channel.msg_ready():
sub_msg = self.client.iopub_channel.get_msg()
msg_type = sub_msg['header']['msg_type']
if msg_type in ['execute_input', 'execute_result']:
sys.stdout.write(u"\\u001b\\u005d133;C\\u001b\\u005c")
}gsx
_E_
)" "$site_packages"/jupyter_console/ptshell.py
fi
if [[ -e "$site_packages"/IPython/terminal/interactiveshell.py ]]; then
echo "Patching $site_packages/IPython/terminal/interactiveshell.py"
perl -0777 -pi -e "$(cat <<'_E_'
s{\Q
if old_loop is not self.pt_loop:
policy.set_event_loop(self.pt_loop)
try:
with patch_stdout(raw=True):
text = self.pt_app.prompt(
default=default,
**self._extra_prompt_options())
\E}
{
if old_loop is not self.pt_loop:
policy.set_event_loop(self.pt_loop)
try:
sys.stdout.write\(u"\\u001b\\u005d133;A\\u001b\\u005c"\)
with patch_stdout(raw=True):
text = self.pt_app.prompt(
default=default,
**self._extra_prompt_options())
}gsx
_E_
)" "$site_packages"/IPython/terminal/interactiveshell.py
fi
if [[ -e "$site_packages"/IPython/core/interactiveshell.py ]]; then
echo "Patching $site_packages/IPython/core/interactiveshell.py"
perl -0777 -pi -e "$(cat <<'_E_'
s{\Q
try:
result = self._run_cell(
raw_cell, store_history, silent, shell_futures)
\E}
{
try:
sys.stdout.write\(u"\\u001b\\u005d133;C\\u001b\\u005c"\)
result = self._run_cell(
raw_cell, store_history, silent, shell_futures)
}gsx
_E_
)" "$site_packages"/IPython/core/interactiveshell.py
fi
# kitty.conf
mouse_map shift+right press ungrabbed paste_from_selection
mouse_map right press ungrabbed mouse_select_command_output
map kitty_mod+s paste_from_selection
Update: providing patches for ipython as well.
I recently upgraded to 0.24 and explored the shell integration features. I was delighted with these features and thought it would be great within my nvim + jupyter console workflow. My current workflow requires a lot of cut+paste from
jupyter consoleto a text file. I was able to hack jupyter console so it works well with the shell integration features. Now, when I run a command, I no longer have to select and then paste. I just get the entire output selected using shell integration and then paste it where I wanted. This required me to insert the escape codes at the right locations in the jupyter_console/ptshell.py file. Everything works like a charm now. I am the relevant patches below for others to try-