Skip to content

Instantly share code, notes, and snippets.

@jcb91
Last active April 27, 2018 11:16
Show Gist options
  • Save jcb91/399206179be7a749c04e209a8d67e564 to your computer and use it in GitHub Desktop.
Save jcb91/399206179be7a749c04e209a8d67e564 to your computer and use it in GitHub Desktop.
add an ssh cell script magic
"""
This cell magic allows one to do things like
In [1]: %%script ssh -T my_wonderful_host.example.com
...: hostname
...: echo done;
my_wonderful_host.example.com
done
"""
from IPython.core.interactiveshell import get_ipython
from traitlets.config.manager import BaseJSONConfigManager
ip = get_ipython()
scripts = list(
ip.magics_manager.magics.get(
'cell')['script'].__self__.script_magics)
if 'ssh' not in scripts:
scripts.append('ssh')
config_manager = BaseJSONConfigManager(
config_dir=ip.profile_dir.location)
config_basename = 'ipython_config'
config_manager.set(config_basename, {
'ScriptMagics': {'script_magics': scripts}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment