Clipboard

Hex.pm

Copy to and paste anything from system clipboard.

Sick of IO.puts(json) then manually selecting your terminal? Try Clipboard.copy(json)!

Wraps ports to system-specific utilities responsible for clipboard access. It uses the default clipboard utilities on macOS, Linux and Windows but can be configured to call any executable.

Examples

Clipboard.copy("Hello, World!")
"Hello, World!"
"Bye, World!"
|> Clipboard.copy() # Insert into pipelines
|> send_to_api()
# And paste too!
Clipboard.paste()
"Bye, World!"

Options

Clipboard uses these utilities by default.

OSUtilities
macOSpbcopy & pbpaste
Linuxxclip
Windowsclip

However, you can instruct Clipboard to use another command by setting config.exs.

config :clipboard,
unix: [
copy: {"xsel", ["-i"]},
paste: {"xsel", ["-o"]},
]

Supported operating systems are :macos, :unix and :windows.

Installation

Add clipboard to your list of dependencies in mix.exs:

def deps do
[{:clipboard, ">= 0.0.0", only: [:dev]}]
end

Don’t forget to update your dependencies.

$ mix deps.get

Caveats

Pasting on Windows doesn’t work out of the box because clip only supports copying.

License

Clipboard is released under MIT license.