• Stars
    star
    350
  • Rank 116,911 (Top 3 %)
  • Language
    Ruby
  • License
    MIT License
  • Created over 13 years ago
  • Updated about 1 month ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Ruby access to the clipboard on Windows, Linux, macOS, Java, Cygwin, and WSL πŸ“‹οΈŽ

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 Repositories

1

irbtools

Improvements for Ruby's IRB console πŸ’ŽοΈŽ
Ruby
912
star
2

paint

Ruby gem for ANSI terminal colors 🎨︎ VERY FAST
Ruby
364
star
3

whirly

Colorful Terminal Spinner for Ruby πŸ˜€οΈŽ
Ruby
323
star
4

idiosyncratic-ruby.com

Documenting All Ruby Specialities πŸ’ŽοΈŽ
JavaScript
310
star
5

uniscribe

Know your Unicode βœ€
Ruby
280
star
6

pws

Command-Line Password Safe πŸ”οΈŽ
Ruby
210
star
7

unicode-emoji

Up-to-date Emoji Regex in Ruby
Ruby
142
star
8

unibits

Visualize different Unicode encodings in the terminal
Ruby
127
star
9

unicode-display_width

Monospace Unicode character width in Ruby
Ruby
117
star
10

sugar_refinery

Tiny refinements for Ruby
Ruby
110
star
11

productive-sublime-snippets-ruby

Ruby Snippets for Sublime Text
Ruby
107
star
12

stdgems

Ruby's default & bundled gems: The new standard library
Ruby
105
star
13

relaxed.ruby.style

A Relaxed Style Guide for Ruby & Configuration for RuboCop
Ruby
72
star
14

fresh

Fresh Ruby Enhanced SHell
Ruby
71
star
15

wirb

Ruby Object Inspection for IRB
Ruby
70
star
16

unicode-confusable

Unicode::Confusable.confusable? "β„œΥ½α–―Κ", "Ruby"
Ruby
68
star
17

sig

Validate Method Arguments & Results in Ruby
Ruby
58
star
18

fancy_irb

Colors & Hash Rockets in IRB
Ruby
48
star
19

rg

A way to integrate AngularJS into a Rails project using CoffeeScript and Bower.
Ruby
46
star
20

debugging

Improve your Print Debugging
Ruby
42
star
21

unicode-x

Unicode Micro Libraries for Ruby
Ruby
38
star
22

characteristics

Character info under different encodings
Ruby
27
star
23

object_shadow

The Shadow of a Ruby Object lets you See and Manipulate its Instance Variables and Methods
Ruby
27
star
24

value_struct

Read-only structs in Ruby
Ruby
25
star
25

redux.rb

A tiny Ruby redux
Ruby
25
star
26

code

Displays a Ruby method's source code
Ruby
24
star
27

has_many_booleans

This Rails plugin/gem allows you to generate virtual boolean attributes, which get saved in the database as a single bitset integer.
Ruby
23
star
28

microevent.rb

Events for Ruby objects (a.k.a objects with Publish-Subscribe capabilities a.k.a. Observer pattern)
Ruby
23
star
29

ruby.style

Collects Ruby Style Guides
CSS
20
star
30

unicopy

Unicode command-line codepoint dumper
Ruby
20
star
31

unicode-blocks

Unicode Blocks of a Ruby String
Ruby
18
star
32

irbtools-more

irbtools-more adds gems to IRB that may not build out-of-the-box
18
star
33

character.construction

Notable characters, codepoints, and resources
HTML
16
star
34

ruby_version

RubyVersion | Better than RUBY_VERSION
Ruby
15
star
35

better-array

Unobtrusive JavaScript Array Extras
JavaScript
15
star
36

render_react

Pre-render and mount React components from Ruby
Ruby
15
star
37

yyid.ex

Almost a random UUID in Elixir
Elixir
14
star
38

rubybuntu-gedit

Ruby/Rails/Web related gedit language definitions, mime types, styles and snippets.
Ruby
14
star
39

slim_migrations

Let's you write slightly slimmer Rails migrations.
Ruby
14
star
40

unicode-name

Unicode character names in Ruby
Ruby
13
star
41

uke

𝄝 Ukulele CLI Support
Ruby
13
star
42

gedit-external-tools

A repository for useful and handy snippets for gedit's external tools plugin
Shell
13
star
43

derb

Dockerfile.erb
Ruby
11
star
44

unicode-scripts

Unicode Scripts / Script Extensions of a Ruby String
Ruby
11
star
45

boolean2

Boolean2 is a Ruby constant that is an ancestor of true and false.
Ruby
11
star
46

az

From A to Z
Ruby
10
star
47

symbolify

␀ ␁ ␂ ␃ ␄ ␅ ␆ ␇ ␈ ␉ ␊ ␋ ␌ ␍ ␎ ␏ ␐ ␑ ␒ ␓ ␔ ␕ ␖ ␗ ␘ ␙ ␚ ␛ ␜ ␝ ␞ ␟ ␠ ␑
Ruby
9
star
48

micrologger

A minimal logger based on MicroEvent.rb
Ruby
9
star
49

watchbuffy

Which Buffy episode to put on next?
Ruby
8
star
50

ruby_info

RubyInfo | Better than SCRIPT_LINES__
Ruby
8
star
51

productive-sublime-snippets-erb

Productive Sublime Snippets for ERB
Ruby
8
star
52

unicoder

(wip)
Ruby
7
star
53

clipboard_formatter

A clipboard formatter for RSpec
Ruby
7
star
54

unicode-categories

Unicode General Categories of a Ruby String
Ruby
7
star
55

microgem

more gems
Ruby
6
star
56

unicode-types

Basic Unicode Types of a Ruby String
Ruby
6
star
57

rubynetz

Example Usage of Harvester
6
star
58

unicode-sequence_name

Unicode sequence names in Ruby
Ruby
6
star
59

Deutsch.rb

Like English.rb
Ruby
6
star
60

unicode-numeric_value

Convert a Unicode character into its numeric value
Ruby
6
star
61

rubybuntu-language-specs

gtksourceview language specifications for Ruby/Web devoloper's gedit
Ruby
6
star
62

ripl-multi_line

This ripl plugin allows you to evaluate multiple lines of code.
Ruby
6
star
63

ruby_engine

RubyEngine | Better than RUBY_ENGINE
Ruby
6
star
64

rubybuntu-mime

gnome mime types for Ruby/Web developer's gedit
5
star
65

promiseUserMedia.js

Promisified access to getUserMedia & vendor prefixes.
JavaScript
5
star
66

added

Module#added
Ruby
5
star
67

procstar

Provides to_proc implementations for other Ruby classes than just Symbol
Ruby
4
star
68

every_day_irb

Ruby
4
star
69

rusty_clipboard

Ruby πŸ‘ͺ Rust πŸ‘ͺ System Clipboard
Ruby
4
star
70

unicode-age

Determine Unicode version required to display a string
Ruby
4
star
71

yyid.rb

Almost a random UUID in Ruby
Ruby
4
star
72

multi_block

Pass multiple blocks to a Ruby method
Ruby
4
star
73

ripl-color_result

This ripl plugin colorizes your results.
Ruby
4
star
74

nem

npm + gem = nem
Ruby
4
star
75

rubybuntu-editor-styles

gtksourceview styles for Ruby/Web devoloper's gedit
4
star
76

ripltools

This meta gem installs a bunch of ripl plugins for a nice-to-use general purpose ripl.
Ruby
4
star
77

named_proc

Named procs and lambdas
Ruby
3
star
78

local_port

Returns the next free local port number to use for your shiny new service
Ruby
3
star
79

nomore

Blocks your computer from accessing domains on the internet
Ruby
3
star
80

cd

Enhanced cd command for the Ruby console.
Ruby
3
star
81

ripl-auto_indent

This ripl plugin indents your multi-line Ruby input.
Ruby
3
star
82

unicode-version

Which level of Unicode and Emoji support is included with Ruby?
Ruby
3
star
83

egonil

Egocentric Nil
Ruby
2
star
84

talk-ruby-unconf-surprises

Ruby is Full of Surprises (Ruby Unconf 2018)
JavaScript
2
star
85

iterate

Kernel#iterate
Ruby
2
star
86

ripl-rocket

Lets you display the ripl result as a comment on the same line.
Ruby
2
star
87

instance_variables_from

Turn bindings, hashes or arrays into instance variables
Ruby
2
star
88

yyid.js

yyid() generates a random uuid* in the browser, uses the crypto api when available
JavaScript
2
star
89

wcswidth-ruby

FFI bindings to libc's wcswidth() to determine the actual display width of strings
Ruby
2
star
90

pws-otp

Experimental OTP support for PWS
Ruby
2
star
91

website

Ruby
2
star
92

null_plus

+nil
Ruby
2
star
93

ripl-color_streams

This ripl plugin colorizes your stdout and stderr streams.
Ruby
2
star
94

yyid-node.js

Almost a random UUID in node.js
JavaScript
1
star
95

yyid.go

Almost a random UUID in Go
Go
1
star
96

communication-map

WebRTC based Location Sharing
CSS
1
star
97

null_question

Adds the null? predicate to Ruby's nil
Ruby
1
star
98

ripl-profiles

This ripl plugin adds a --profile option to ripl that loads profile files in ~/.ripl/profiles before starting ripl
Ruby
1
star
99

exists

Turns null objects into nil
Ruby
1
star