janlelis/clipboard


Ruby access to the clipboard on Windows, Linux, macOS, Java, Cygwin, and WSL 📋︎

License: MIT

Language: Ruby

Keywords: clipboard, cygwin, java, linux, macos, ruby, windows


Clipboard Ruby Gem version

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

  • Linux
  • MacOS
  • Windows
  • Cygwin (POSIX environment for Windows)
  • WSL (Windows Subsystem for Linux)
  • Gtk+ (Cross Platform Widget Toolkit)
  • Java (on JRuby)

Usage

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

Supported Rubies

  • 2.6, 2.5, 2.4, 2.3

Unsupported, but might still work:

  • 2.2, 2.1, 2.0, 1.9

Setup

Add the following lines to your Gemfile:

gem "clipboard"
gem "ffi", :platforms => [:mswin, :mingw] # Required by Clipboard on Windows
  • Important note for Linux users: The clipboard requires the xsel or the xclip command-line program. On debian and ubuntu, xsel can be installed with: sudo apt-get install xsel

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

Alternative Clipboard Providers

There are two implementations included in this gem, which are not used 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 = Clipboard::Java

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

GTK+

Activate with: Clipboard.implementation = Clipboard::Gtk

This utilizes the GTK+ library. See Ruby-GNOME2 for more info.

Requires the gtk3 or gtk2 gem to be installed.

Tips & Tricks

Linux: Using Clipboard via SSH

To be able to use the clipboard through SSH, 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: Paste From Specific X11 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 an argument. The default is :clipboard, other options are :primary and :secondary.

Clipboard.copy always copies to all three clipboards.

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 file content to your clipboard:

$ blip FILE_NAME

Without any arguments, it will just paste the contents of the clipboard.

MIT

Copyright (c) 2010-2019 Jan Lelis http://janlelis.com released under the MIT license. Contributions by and thanks to Michael Grosser and all the other contributors!

Project Statistics

Sourcerank 13
Repository Size 156 KB
Stars 267
Forks 28
Watchers 11
Open issues 0
Dependencies 3
Contributors 12
Tags 28
Created
Last updated
Last pushed

Top Contributors See all

Jan Lelis Michael Grosser ushi brian m. carlson Bohdan Zhuravel Travis Dunn Cédric Luthi Jay Kim William Woodruff momo-lab Shiang-Yuan Kao Nobuhiro Tachino

Packages Referencing this Repo

clipboard
Access to the clipboard on Linux, MacOS, Windows, and Cygwin: Clipboard.copy, Clipboard.paste, Cl...
Latest release 1.3.3 - Updated - 267 stars

Recent Tags See all

1.3.3 January 10, 2019
1.3.2 December 14, 2018
1.3.1 December 11, 2018
v1.3.0 December 11, 2018
1.2.1 December 10, 2018
1.2.0 December 09, 2018
1.1.2 May 27, 2018
1.1.2 May 27, 2018
1.1.1 July 24, 2016
1.1.0 March 14, 2016
1.0.6 February 18, 2015
1.0.5 April 30, 2013
1.0.4 April 23, 2013
1.0.3 April 22, 2013
1.0.2 April 21, 2013

Interesting Forks See all

ConradIrwin/clipboard
Access the clipboard on Linux, MacOS and Windows
Ruby - MIT - Updated - 2 stars
hallvors/clipboard
Access the clipboard on Linux, MacOS and Windows
Ruby - MIT - Last pushed - 1 stars
doubleotoo/clipboard
Access the clipboard on Linux, MacOS and Windows
Ruby - MIT - Updated - 1 stars
rking/clipboard
Access the clipboard on Linux, MacOS and Windows
Ruby - MIT - Updated - 1 stars
iMagesh/clipboard
Access the clipboard on Linux, MacOS and Windows
Ruby - MIT - Updated - 1 stars

Something wrong with this page? Make a suggestion

Last synced: 2019-01-10 14:43:07 UTC

Login to resync this repository