Skip to content

Instantly share code, notes, and snippets.

@tgarc
Last active August 22, 2023 15:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tgarc/7b2e918320cc3336af182a1298bd9546 to your computer and use it in GitHub Desktop.
Save tgarc/7b2e918320cc3336af182a1298bd9546 to your computer and use it in GitHub Desktop.
Launch ipython terminal magic
'''
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