diff options
Diffstat (limited to '52-osc.pl')
-rw-r--r-- | 52-osc.pl | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/52-osc.pl b/52-osc.pl new file mode 100644 index 0000000..c73c261 --- /dev/null +++ b/52-osc.pl @@ -0,0 +1,42 @@ +#! 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 + +This is adapted from https://gist.github.com/ojroques/30e9ada6edd9226f9cc1d6776ece31cc +to use the actual system clipboard instead of the urxvt selection. +=cut + +use Clipboard; +use MIME::Base64; +use Encode; + +my %clip_map = ('c' => "clipboard", 'p' => "primary", 's' => "secondary"); + +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 = $Clipboard::driver->paste_from_selection($clip_map{$clip}); + 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 + $Clipboard::driver->copy_to_selection($clip_map{$clip}, $data_decoded); + } + + () +} |