An open API service indexing awesome lists of open source software.

https://github.com/beeender/richclip


https://github.com/beeender/richclip

Last synced: 9 months ago
JSON representation

Awesome Lists containing this project

README

          

# richclip - Command line clipboard utility for multiple platforms

`richclip` is created for [richclip.nvim](https://github.com/beeender/richclip.nvim)
which intends to copy rich text format of source code from neovim with
highlights to the system clipboard. But it can also be used as a standalone
command line utility as an alternative to [xclip](https://github.com/astrand/xclip),
[xsel](https://github.com/astrand/xclip), [wl-clipboard](https://github.com/bugaevc/wl-clipboard)
or other command line clipboard tools.

- Supports Multiple environments. Xorg, Wayland and macOS are supported by the current
version. Windows is planned.
- Recognizes the environment automatically, and choose the right clipboard to
use.
- Supports multiple content with different mime-types simultaneously. A typical
use case is to have the plain source code with mime-type `text/plain` and
highlighted HTML format code with mime-type `text/html` copied, so the client
can choose the preferred content type to paste.

## Installing

### Arch Linux

Install `richclip` from the [AUR](https://aur.archlinux.org/packages/richclip).

### macOS & Other Linux Distributions

Download the static linked binary from the [release page](https://github.com/beeender/richclip/releases).

### Windows

Not supported yet

## Usage

### Paste

```
❯ richclip paste --help
Paste the data from clipboard to the output
Usage: richclip paste [OPTIONS]
Options:
-l, --list-types List the offered mime-types of the current clipboard only without the contents
-t, --type Specify the preferred mime-type to be pasted
-p, --primary Use the 'primary' clipboard
-h, --help Print help
```

### Copy

```
❯ richclip copy --help
Receive and copy data to the clipboard
Usage: richclip copy [OPTIONS]

Options:
-p, --primary Use the 'primary' clipboard
--foreground Run in foreground
--one-shot Enable one-shot mode, anything received from stdin will be copied as it is
-t, --type [] Specify mime-type(s) to copy and implicitly enable one-shot copy mode
-h, --help Print help
```

#### Bulk mode copy

By default, `richclip` receives data in bulk mode. In this mode, multiple formats
of data can be copied to the clipboard with multiple mime-types. This allows
the paste side to choose the favorite format of data to use.

The data to be copied to the clipboard needs to follow a simple protocol which
is described as below.

| Item | Bytes | Content |
|------------------| :------- | :------------------ |
| Magic | 4 | 0x20 0x09 0x02 0x14 |
| Protocol Version | 1 | 0x00 |
| Section Type | 1 | 'M' |
| Section Length | 4 | 0x00 0x00 0x00 0x0a |
| Section Data | 10 | "text/plain" |
| Section Type | 1 | 'M' |
| Section Length | 4 | 0x00 0x00 0x00 0x04 |
| Section Data | 4 | "TEXT" |
| Section Type | 1 | 'C' |
| Section Length | 4 | 0x00 0x00 0x00 0x09 |
| Section Data | 9 | "SOME Data" |
| Section Type | 1 | 'M' |
| Section Length | 4 | 0x00 0x00 0x00 0x09 |
| Section Data | 9 | "text/html" |
| Section Type | 1 | 'C' |
| Section Length | 4 | 0x00 0x00 0x00 0x09 |
| Section Data | 9 | "HTML code" |

- Every section starts with the section type, `M` (mime-type) or `C` (content).
- Before `C` section, there must be one or more `M` section to indicate the data type.
- Section length will be parsed as big-endian uint32 number.

#### One-shot mode copy

This is the traditional way to copy data like other clipboard utilities. The
mime-types can be specified through the command line, and all data received
through `stdin` will be copied as it is.

```bash
# Copy "TestData" to the clipboard, with default mime-type
echo TestData | richclip copy --one-shot

# Copy "Haha" to the clipboard, as "text/html" and "HTML"
echo "Haha" | richclip copy --type "text/html" --type "HTML"
```