ProductPromotion
Logo

Ruby

made by https://0x3d.site

GitHub - janlelis/clipboard: Ruby access to the clipboard on Windows, Linux, macOS, Java, WSL and more platforms 📋︎
Ruby access to the clipboard on Windows, Linux, macOS, Java, WSL and more platforms 📋︎ - janlelis/clipboard
Visit Site

GitHub - janlelis/clipboard: Ruby access to the clipboard on Windows, Linux, macOS, Java, WSL and more platforms 📋︎

GitHub - janlelis/clipboard: Ruby access to the clipboard on Windows, Linux, macOS, Java, WSL and more platforms 📋︎

Clipboard Ruby Gem 📋︎ version [ci]

Lets you access the system clipboard from everywhere. Currently supported platforms:

  • Linux (X11)
  • Linux (Wayland)
  • MacOS
  • Windows
  • Cygwin (POSIX environment for Windows)
  • WSL (Windows Subsystem for Linux)
  • Gtk+ (Cross Platform Widget Toolkit)
  • Java (on JRuby)
  • Experimental: OSC52 (ANSI escape sequence) only copying - see note below

Supported Rubies: 3.3, 3.2, 3.1, 3.0

Unsupported, but might still work: 2.X (use clipboard gem version 1.x)

Usage

  • Clipboard.copy - Copies a string to system clipboard
  • Clipboard.paste - Paste text contents from system clipboard as string
  • Clipboard.clear - Empties the system clipboard

Setup

Run 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:

  • On X11: xsel or xclip
  • On Wayland: wl-copy and wl-paste (wl-clipboard) - depending on your system, just having xsel / xclip might also work

Clipboard Implementations

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 = ...

Alternative Clipboard Providers

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:

Java

Activate with: Clipboard.implementation = :java

This is an option for JRuby users which will use the clipboard functionality from the Java standard library.

GTK+

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.

OSC52

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 provider 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.

Tips & Tricks

Linux: Using Clipboard via SSH

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.

Linux: Copy To or Paste From Specific Clipboard / Selection

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: Encoding Info

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')

CLI Utility: blip

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.

MIT

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!

More Resources
to explore the angular.

mail [email protected] to add your project or resources here 🔥.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory