Created
March 29, 2022 07:24
IPython magic for copying into clipboard in zsh shell on macOS.
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
from IPython.core.magic import needs_local_scope, register_line_magic | |
@register_line_magic | |
@needs_local_scope | |
def clip(line, local_ns): | |
import json | |
import os | |
import subprocess | |
value = local_ns[line] | |
subprocess.check_call( | |
[ | |
os.environ["SHELL"], | |
"-ic", | |
"echo {} | clipcopy".format(json.dumps(value)), | |
], | |
stdout=subprocess.DEVNULL, | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment