Created
August 29, 2022 17:18
-
-
Save kenichi/f11a9f457e6189df7257ccc209c10924 to your computer and use it in GitHub Desktop.
IEX clipboard helper
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
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