Last active
April 27, 2018 11:16
-
-
Save jcb91/399206179be7a749c04e209a8d67e564 to your computer and use it in GitHub Desktop.
add an ssh cell script magic
This file contains 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
""" | |
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