Skip to content

Instantly share code, notes, and snippets.

@linw1995
Created March 29, 2022 07:24
Show Gist options
  • Save linw1995/552eac751f75a8f96799d0408d320224 to your computer and use it in GitHub Desktop.
Save linw1995/552eac751f75a8f96799d0408d320224 to your computer and use it in GitHub Desktop.
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