Last active
August 22, 2023 15:52
-
-
Save tgarc/7b2e918320cc3336af182a1298bd9546 to your computer and use it in GitHub Desktop.
Launch ipython terminal magic
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Adds %ipython magic command to launch a bash terminal and connect to the current jupyter session because coding in jupyter sucks. | |
To be placed in ~/.ipython/profile_default/startup/ | |
''' | |
import os, sys | |
import ipykernel | |
from IPython.core.magic import register_line_magic | |
@register_line_magic | |
def ipython(line): | |
fn = ipykernel.get_connection_file() | |
if sys.platform.lower().startswith('win'): | |
cmd = '''wt -- "%%ProgramFiles%%/Git/bin/bash.exe" -i -l -c "jupyter console --existing '%s'"''' % fn | |
os.system(cmd) | |
print("Use Ctrl-D to exit console without killing kernel") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment