Created
January 17, 2021 11:54
-
-
Save ojroques/30e9ada6edd9226f9cc1d6776ece31cc to your computer and use it in GitHub Desktop.
Enable support of OSC52 for urxvt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! perl | |
=head1 NAME | |
52-osc - Implement OSC 52 ; Interact with X11 clipboard | |
=head1 SYNOPSIS | |
urxvt -pe 52-osc | |
=head1 DESCRIPTION | |
This extension implements OSC 52 for interacting with system clipboard | |
Most code stolen 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/); | |
} | |
() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment