Skip to content

Instantly share code, notes, and snippets.

@linw1995
Created March 29, 2022 07:24
IPython magic for copying into clipboard in zsh shell on macOS.
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