Giter VIP home page Giter VIP logo

tty-copy's Introduction

tty-copy

Binaries Workflow Packaging status

A utility for copying content to the system clipboard from anywhere via a TTY and terminal using the ANSI OSC52 sequence. It works in any terminal session, whether local, remote (e.g. SSH), or even nested therein!

Refer to tty-copy(1) for usage information.

Supported Terminals

Here is a non-exhaustive list of the status of popular terminal emulators regarding OSC52 [1]:

Terminal OSC 52 support

Alacritty

yes

Contour

yes

far2l

yes

foot

yes

GNOME Terminal (and other VTE-based terminals)

not yet

iTerm2

yes

kitty

yes

Konsole

not yet

QTerminal

not yet

rxvt

yes (to be confirmed)

screen

yes

Terminal.app

no, but see workaround

tmux

yes

urxvt

yes (with a script, see here)

Windows Terminal

yes

Requirements

Runtime:
  • UNIX-like system

Build:
  • C compiler and linker supporting at least C99 (tested with clang and gcc)

  • GNU Make

  • Asciidoctor (for building man pages)

Installation

On Alpine Linux

Install package tty-copy from the Alpine’s community repository:

apk add tty-copy

On Arch Linux

Install package tty-copy from AUR:

yay -S tty-copy

Or use another AUR helper.

On Fedora

Install package tty-copy from the Fedora repositories (since Fedora 35):

dnf install tty-copy

Using Pre-Built Binary

🐧 Linux: [x86_64] [aarch64] [armv7] [ppc64le] [riscv64]
macOS: [x86_64]

  1. Download and verify tty-copy binary for your CPU architecture (pick the right link from the list above), for example:

    curl -sSLO https://github.com/jirutka/tty-copy/releases/download/v0.2.2/tty-copy.x86_64-linux
    curl -sSL https://github.com/jirutka/tty-copy/releases/download/v0.2.2/checksums.txt | sha256sum -c --ignore-missing
  2. Install tty-copy somewhere on your PATH, e.g. /usr/local/bin:

    install -m 755 tty-copy.* /usr/local/bin/tty-copy

All binaries are statically linked with musl libc, so they work on every Linux system (distro) regardless of used libc.

From Source Tarball

wget https://github.com/jirutka/tty-copy/archive/v0.2.2/tty-copy-0.2.2.tar.gz
tar -xzf tty-copy-0.2.2.tar.gz
cd tty-copy-0.2.2

make build
make install DESTDIR=/ prefix=/usr/local

Credits

This program is inspired from termcopy and vim-oscyank.

License

This project is licensed under MIT License. For the full text of the license, see the LICENSE file.


1. This list was originally copied from vim-oscyank.

tty-copy's People

Contributors

christianparpart avatar da2x avatar hroncok avatar jirutka avatar pubis avatar unxed avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

tty-copy's Issues

Add support for paste

Reading the OSC52 spec it appears that it supports pasting as well as copying. This would be useful :)

Doesn't work in tmux 3.3_a with tmux term type

Environment:

  • Distro: Arch Linux
  • Terminal: foot 1.13.1
  • tmux 3.3_a
  • tty-copy 0.2.2

Running in a new tmux session with the following config
tmux.conf

set-option -ga terminal-features ',foot:clipboard'
set-option -g set-clipboard on

Settings are applied correctly as can be seen in the following commands executed in the tmux session

$ tmux show -s set-clipboard
set-clipboard on

$ tmux info | grep Ms:
 192: Ms: (string) \033]52;%p1%s;%p2%s\a   # <- for this to be correct, TERM should be set to foot before entering the tmux session

$ tmux show -s terminal-features
terminal-features[0] xterm*:clipboard:ccolour:cstyle:focus:title
terminal-features[1] screen*:title
terminal-features[2] foot:clipboard

When tty-copy detects that term type is tmux, or when manually forcing this with --term tmux option, then it doesn't copy to the clipboard correctly.
The issue resolves when forcing screen as term type, or when setting TERM to a different value than screen.

No such problem when not in tmux session.

My current solution is to force screen term type using an environment variable.

diff --git a/tty-copy.c b/tty-copy.c
index 8dca4ca..d8ecd0d 100644
--- a/tty-copy.c
+++ b/tty-copy.c
@@ -145,7 +145,7 @@ static void parse_opts (int argc, char * const *argv) {
                opts.tty_path = _PATH_TTY;
        }

-       const char *term = NULL;
+       const char *term = NULL, *tmux_override = NULL;
        if (term_type != NULL) {
                opts.is_screen = str_equal(term_type, "screen");
                opts.is_tmux = str_equal(term_type, "tmux");
@@ -154,8 +154,11 @@ static void parse_opts (int argc, char * const *argv) {
                if (str_startswith(term, "screen")) {
                        // Since tmux defaults to setting TERM=screen (ugh), we need to detect
                        // it here specially.
-                       if (getenv("TMUX") != NULL) {
-                               opts.is_tmux = true;
+                       tmux_override = getenv("TTYCOPY_TMUX_OVERRIDE");
+                       if (getenv("TMUX") != NULL &&
+                               (tmux_override == NULL ||
+                               strcmp(tmux_override, "1") != 0 )) {
+                                       opts.is_tmux = true;
                        } else {
                                opts.is_screen = true;
                        }

Warning on compile on macOS 12.3

I'm running macOS 12.3 on x86_64, current with all patches. I'm not sure if I have something weird with my system, but I'm running into a warning when building from source.

❯ make build
cc -Os -DNDEBUG -std=c11 -DVERSION='"0.2.0-2-g166b8ab"' -o build/tty-copy.o -c tty-copy.c
tty-copy.c:256:13: warning: passing 'uchar [16]' to parameter of type 'const char *' converts between pointers to integer types where one is of the unique plain 'char' type and the other is not [-Wpointer-sign]
        if (sscanf(buf, "\033[%d;%dR", &row, &col) != 2) {
                   ^~~
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/stdio.h:181:36: note: passing argument to parameter here
int      sscanf(const char * __restrict, const char * __restrict, ...) __scanflike(2, 3);
                                       ^
1 warning generated.
cc  -o build/tty-copy build/tty-copy.o
asciidoctor -b manpage -o build/tty-copy.1 tty-copy.1.adoc
rm build/tty-copy.o

This doesn't seem to impact basic functionality (and I'm not sure how this code is invoked to try and test it fully for any issues). So I wouldn't consider this a serious problem, but still, I wanted to bring it up.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.