3

The OSC52 escape sequence tells the terminal to put arbitrary text in the system clipboard. I want to use this fact to be able to copy to the local clipboard from a remote Vim session through ssh, as explained here. However, I am getting conflicting information on whether the terminal I use, urxvt (also called rxvt-unicode) supports this escape sequence.

I have found a perl script that may or may not implement this functionality, called clipboard-osc, and I have added it to my urxvt configuration file ~/.Xdefaults with the line URxvt.perl-ext-common: clipboard-osc. I haven't been able to make it work, and the information on this perl script (and on escape sequences in urxvt in general) is very scarce.

So, does urxvt support the OSC52 escape sequence for clipboard integration? And if so, how can I use it and what are the possible pitfalls to avoid?

1 Answer 1

4

I figured out a solution to my problem. I will post it here for future reference.

urxvt does not support the OSC52 escape sequence by default, which is a pity. However, urxvt is highly extensible through perl scripts, so there are perl scripts out there that add suppport for OSC52. An example is this small script by GitHub user parantapa. With this, you can add support for OSC52 in two simple steps:

  • Copy the script to ~/.urxvt/ext/52-osc
  • Source it in urxvt by adding the following line to your ~/.Xdefaults configuration file: URxvt.perl-ext-common: 52-osc

For completeness and future-proofness, here is the full script.

#! perl

=head1 NAME
52-osc - Implement OSC 32 ; Interact with X11 clipboard
=head1 SYNOPSIS
   urxvt -pe 52-osc
=head1 DESCRIPTION
This extension implements OSC 52 for interacting with system clipboard
Copied from GitHub user parantapa, who also reports most code came from:
http://ailin.tucana.uberspace.de/static/nei/*/Code/urxvt/
=cut

use MIME::Base64;
use Encode;

sub on_osc_seq {
    my ($term, $op, $args) = @_;
    return () unless $op eq 52;

    my ($clip, $data) = split ';', $args, 2;
    if ($data eq '?') {
        my $data_free = $term->selection();
        Encode::_utf8_off($data_free); # XXX
        $term->tt_write("\e]52;$clip;".encode_base64($data_free, '')."\a");
    }
    else {
        my $data_decoded = decode_base64($data);
        Encode::_utf8_on($data_decoded); # XXX
        $term->selection($data_decoded, $clip =~ /c/);
        $term->selection_grab(urxvt::CurrentTime, $clip =~ /c/);
    }

    ()
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .