# yank for Terminal Field Selection and Clipboard Copying

> yank is a small C utility that turns piped terminal output into a keyboard-driven field selector. It fits Linux, macOS, and BSD workflows where mouse selection or a terminal multiplexer would be inconvenient, but its usefulness depends on an available command that consumes copied text.

**mptre/yank** — Yank terminal output to clipboard

- Repository: https://github.com/mptre/yank
- Stars: 1,716 · Forks: 48
- Language: C
- License: MIT
- Published: 2026-10-16 · Updated: 2026-10-16 · Language: en
- Canonical page: https://hysenlabs.com/projects/mptre-yank

## Why yank Exists for Piped Terminal Data

yank addresses a narrow but common terminal problem: command output contains several fields, and copying one field normally requires mouse selection or terminal-specific copy mode. The README identifies mouse use as a cache miss for this task and says the author wanted a solution that did not require a terminal multiplexer. That makes yank a terminal-agnostic bridge between Unix pipelines and interactive selection.

The intended users are people who already work with environment variables, CSV records, process listings, compiler diagnostics, and command output redirected through pipes. A producer does not need to understand clipboard tools. It writes text to `stdin`, yank presents that text as selectable fields, and the chosen value is sent to a clipboard command. This is useful when the exact field to copy is not known in advance, such as a column from `env` or a process ID from `ps`.

The utility is not a general-purpose clipboard manager. Its documented scope is selecting fields from input and forwarding the result to another command. It does not retain clipboard history, synchronize files, or replace the terminal emulator. Its dependency on an interactive selection interface also means it belongs at the point in a pipeline where a person is present to choose a value.

## How yank Selects Fields and Reaches the Clipboard

According to the README, yank reads from `stdin` and opens a selection interface. Fields can be produced in two ways. The `-d` option splits input on a delimiter sequence, while `-g` recognizes fields with a regular expression. Arrow keys move between fields, and the interface supports Emacs-style and Vi-style bindings. The README directs users to `yank(1)` for the full binding reference rather than claiming that one command layout covers every terminal.

After the user presses return, yank invokes its configured yank command. The default is `xsel`, and anything supplied after `--` replaces that command for the invocation. The external command receives the selected field on `stdin`. For example, `xsel -b` changes the destination from the default primary clipboard to the clipboard buffer. This command indirection is yank's main integration point. It keeps clipboard handling outside the C program and permits commands such as `pbcopy` or `shcopy` when they are configured at build time.

There is also a pipeline-friendly exception. If `stdout` is not a terminal, yank writes the selected field to `stdout` and exits without invoking the clipboard command. This allows the selection to feed another program, as the `ps ux | yank -g [0-9]+ | xargs kill` example demonstrates. The distinction is important: interactive clipboard mode and stdout forwarding are separate operating modes, selected by whether stdout is attached to a terminal.

## Installing yank Across Packaged Systems

The README provides package-manager instructions for Arch Linux, Debian, Fedora, Nix or NixOS, openSUSE, macOS through Homebrew and MacPorts, FreeBSD, and OpenBSD. Package names are generally `yank`, although Debian and Fedora install the executable as `/usr/bin/yank-cli` because of a naming conflict.

On Debian, the documented installation command is:

```sh
$ sudo apt-get install yank
```

On macOS with Homebrew, use:

```sh
$ brew install yank
```

The package installation path is the simplest choice when a maintained package is already available for the target system. Users should check the executable name after installation on Debian or Fedora. The README also states that Fedora provides manual pages under both `yank` and `yank-cli`.

For a source installation, the Makefile builds the `yank` program from `yank.o` and links the C source. The default installation directory is `/usr/local`, and `make install` installs the binary and `yank.1`:

```sh
$ make install
```

The install destination can be changed with `PREFIX`:

```sh
$ make PREFIX=DIR install
```

The source build also exposes `CFLAGS`, `CPPFLAGS`, and `LDFLAGS` through the Makefile, but the README does not provide a complete portability recipe for an unsupported system.

## First Uses with Delimiters, Regexes, and Pipelines

Start with an environment variable listing. The `-d` option uses `=` as the delimiter, so the user can move between variable names and values before pressing return:

```sh
$ env | yank -d =
```

For CSV data, the documented delimiter is a comma followed by a space. The exact example from the README is:

```sh
$ yank -d ", <file.csv
```

This command sends the file into yank's selection interface. The delimiter sequence, including the space, matters because the README describes the option as splitting on a sequence rather than on a single character.

When the desired field is defined by a pattern, `-g` uses a regular expression. The following example selects a process ID and then passes it to `xargs`:

```sh
$ ps ux | yank -g [0-9]+ | xargs kill
```

This example also illustrates the non-terminal stdout mode. Because `xargs` is downstream, yank does not invoke its configured clipboard command; it writes the selected value into the pipeline. That behavior should be checked carefully in scripts because a human still chooses the field before the downstream command receives it.

For a whole line, use `-l`:

```sh
$ make 2>&1 | yank -l
```

The README says the selected field is copied with the default primary clipboard. To request a different destination, pass a command after `--`:

```sh
$ yank -- xsel -b
```

These examples cover the main documented choices: delimiter splitting, regular-expression matching, whole-line selection, clipboard output, and forwarding to another command.

## Choosing the Compile-Time Clipboard Command

The Makefile defines the default clipboard command as `YANKCMD=xsel` and passes it to the C build through `CPPFLAGS`. This is a build-time default, not a documented runtime configuration file. The README gives two examples of replacing it during installation.

macOS users can select `pbcopy`:

```sh
$ make YANKCMD=pbcopy
```

For synchronization from an SSH session or a headless environment, the README identifies `shcopy` as an option:

```sh
$ make YANKCMD=shcopy
```

The repository does not explain the setup requirements for `shcopy`, so the example establishes the intended command choice but does not provide enough information to configure the remote side. Similarly, the README does not claim that yank installs `xsel`. A system with yank but no compatible clipboard utility can therefore fail when the interactive selection is accepted.

The command after `--` is narrower. It changes the command for one invocation and still receives the selected value on `stdin`. The README only demonstrates `xsel -b`; it does not document shell expansion, quoting rules, or a general command syntax beyond stating that everything after `--` is used as the yank command. Teams should treat this as an explicit interface and avoid assuming that arbitrary command construction has been tested.

## Limitations, Alternatives, and Maintenance

The main limitation is the need for a usable clipboard backend and an interactive terminal. yank is unsuitable for a fully unattended script because the user must move the selection and press return. It is also a poor fit for environments where the output is too large for a comfortable selection interface, although the README does not define a maximum input size. Terminal compatibility beyond the documented key bindings is not explained, so users should verify their terminal before relying on it.

The README presents two practical alternatives. A terminal multiplexer can provide copy operations inside a managed session, but it adds a layer that the author explicitly wanted to avoid. The other approach is mouse selection or terminal-native selection. yank differs by treating the input as data first and exposing field-level keyboard selection through a small standalone program. It is therefore better suited to short, structured output than to arbitrary scrollback selection.

The repository is not archived. Its last push was on 2026-07-16, and version `v1.4.0` was released on 2026-07-16. That is recent recorded development activity, but the repository does not promise a release cadence. The maintenance cost is low in terms of project size, based on the single `yank.c` source file and compact Makefile, while upgrades still require checking changes to the `YANKCMD` default, selection behavior, and package-specific executable names. The project is distributed under the MIT license. That identifies the license, but users and distributors remain responsible for following its terms.

## Conclusion

Adopt yank for keyboard-driven clipboard work in Linux, macOS, or BSD terminals when piping output through an interactive selector is acceptable. Do not choose it for non-interactive pipelines, headless systems without a suitable clipboard command, or users who want a terminal multiplexer rather than a standalone filter. Verify the installed binary name, the selected clipboard mechanism, and the behavior of your shell and terminal before integrating it into scripts.

## FAQ

### How do I install yank on Debian or macOS?

On Debian, the README gives `sudo apt-get install yank`, but notes that the executable is installed as `/usr/bin/yank-cli` because of a naming conflict. On macOS with Homebrew, it gives `brew install yank`.

### How do I select an environment variable value with yank?

Pipe the environment listing through yank with `env | yank -d =`. The `-d` option splits fields on the `=` delimiter, after which the arrow keys and return key select and copy a field.

### Can yank copy to a different clipboard selection?

Yes. The README uses `yank -- xsel -b` to select the clipboard buffer instead of the default primary clipboard. The command after `--` receives the selected field on `stdin`.

### Does yank work without xsel?

The documented default is `xsel`, but the build can define another command with `YANKCMD`. The README specifically gives `pbcopy` for macOS and `shcopy` for synchronization from SSH or headless environments.

## Sources

- [Issues](https://github.com/mptre/yank/issues)
- [License: MIT](https://github.com/mptre/yank/blob/master/LICENSE)
- [mptre/yank on GitHub](https://github.com/mptre/yank)
- [README](https://github.com/mptre/yank/blob/master/README.md)
- [Releases](https://github.com/mptre/yank/releases)

---

Hysen Labs editorial analysis, written from the project's own repository and release notes. Cite the canonical page: https://hysenlabs.com/projects/mptre-yank
