Skip to content

Instantly share code, notes, and snippets.

@kenichi
Created August 29, 2022 17:18
Show Gist options
  • Save kenichi/f11a9f457e6189df7257ccc209c10924 to your computer and use it in GitHub Desktop.
Save kenichi/f11a9f457e6189df7257ccc209c10924 to your computer and use it in GitHub Desktop.
IEX clipboard helper
defmodule KEx do
@moduledoc "custom IEx extensions"
@doc """
Send data to `pbcopy`, a macOS utility that reads STDIN into the clipboard.
"""
def pbcopy(data) do
port = Port.open({:spawn, "/usr/bin/pbcopy"}, [:binary])
send(port, {self(), {:command, data}})
send(port, {self(), :close})
receive do
{^port, :closed} -> :ok
other -> {:error, other}
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment