Security News
pnpm 10.0.0 Blocks Lifecycle Scripts by Default
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Lets you access the system clipboard from everywhere. Currently supported platforms:
Supported Rubies: 3.3, 3.2, 3.1, 3.0
Unsupported, but might still work: 2.X (use clipboard gem version 1.x)
Clipboard.copy
- Copies a string to system clipboardClipboard.paste
- Paste text contents from system clipboard as stringClipboard.clear
- Empties the system clipboardRun gem install clipboard
(and gem install ffi
on Windows) or add the following lines to your Gemfile
:
gem "clipboard"
gem "ffi", :platforms => [:mswin, :mingw] # Necessary on Windows
Important note for Linux users: The clipboard gem requires additional programs to be available:
In most environments, the appropriate clipboard implementation can be detected automatically. If none is found, the gem will fallback to a file based one, which will just write to/read from ~/.clipboard
instead of the system clipboard.
You can check the implementation used with Clipboard.implementation
or set a specific implementation with Clipboard.implementation = ...
There are more implementations included in this gem, which are not activated by default. You can opt-in to use them if you think they are a better fit for your application environment:
Activate with: Clipboard.implementation = :java
This is an option for JRuby users which will use the clipboard functionality from the Java standard library.
Activate with: Clipboard.implementation = :gtk
This utilizes the GTK+ library. See Ruby-GNOME2 for more info.
Requires the gtk3
or gtk2
gem to be installed.
Activate with: Clipboard.implementation = :osc52
OSC52 is an ANSI escape sequence that some terminals support to access the system clipboard. One advantage of using this clipboard proider is that it is possible to copy from remote ssh sessions to your system clipboard.
As of the current version, only copy and clear commands are supported (no paste).
Please note: Even if your terminal includes OSC52 functionality, the feature could be (partially) disabled to prevent malicious scripts from accessing (or setting) your clipboard.
To be able to use the clipboard through SSH (using the xsel
/xclip
based implementation), you need to install xauth
on your server and connect via ssh -X
or ssh -Y
. Please note that some server settings restrict this feature.
The clipboard on Linux is divided into multiple clipboard selections. You can choose from which clipboard you want to paste
from by passing it as the first argument. The default is :clipboard, other options are :primary and, for some implementations, :secondary:
Clipboard.paste("primary") # or
Clipboard.paste(clipboard: "primary")
Clipboard.copy
will copy to all available clipboards, except if you specifiy a clipboard using the clipboard:
keyword argument:
Clipboard.copy("only goes to primary clipboard", clipboard: "primary")
Windows uses UTF-16LE as its default encoding, so pasted strings will always come in UTF-16. You can then manually convert them to your desired encoding, for example, UTF-8, using the String#encode method:
Clipboard.paste.encode('UTF-8')
The blip gem is a handy command-line wrapper for the clipboard gem. It lets you quickly copy a file's content to your clipboard:
$ blip FILE_NAME
Without any arguments, it will just paste the contents of the clipboard.
Copyright (c) 2010-2024 Jan Lelis https://janlelis.com released under the MIT license. Contributions by and thanks to Michael Grosser and all the other contributors!
FAQs
Unknown package
We found that clipboard demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.