67 lines
1.3 KiB
Perl
67 lines
1.3 KiB
Perl
#! perl -w
|
|
# Author: Bert Muennich
|
|
# Website: http://www.github.com/muennich/urxvt-perls
|
|
# License: GPLv2
|
|
|
|
# Use keyboard shortcuts to copy the selection to the clipboard and to paste
|
|
# the clipboard contents (optionally escaping all special characters).
|
|
# Requires xsel to be installed!
|
|
|
|
# Usage: put the following lines in your .Xdefaults:
|
|
# URxvt.perl-ext-common: clipboard
|
|
# URxvt.keysym.M-c: perl:clipboard:copy
|
|
# URxvt.keysym.M-v: perl:clipboard:paste
|
|
# URxvt.keysym.M-C-v: perl:clipboard:paste_escaped
|
|
|
|
# The use of the functions should be self-explanatory!
|
|
|
|
use strict;
|
|
use utf8;
|
|
|
|
sub copy {
|
|
my ($self) = @_;
|
|
|
|
open(CLIPBOARD, "| xsel -ib");
|
|
my $sel = $self->selection();
|
|
utf8::encode($sel);
|
|
print CLIPBOARD $sel;
|
|
close(CLIPBOARD);
|
|
|
|
()
|
|
}
|
|
|
|
sub paste {
|
|
my ($self) = @_;
|
|
|
|
my $str = `xsel -ob`;
|
|
$str =~ tr/\n/\r/;
|
|
$self->tt_write($str);
|
|
|
|
()
|
|
}
|
|
|
|
sub paste_escaped {
|
|
my ($self) = @_;
|
|
|
|
my $str = `xsel -ob`;
|
|
$str =~ tr/\n/\r/;
|
|
$str =~ s/([!#\$%&\*\(\) ='"\\\|\[\]`~,<>\?])/\\\1/g;
|
|
$self->tt_write($str);
|
|
|
|
()
|
|
}
|
|
|
|
sub on_user_command {
|
|
my ($self, $cmd) = @_;
|
|
|
|
if ($cmd eq "clipboard:copy") {
|
|
$self->copy;
|
|
} elsif ($cmd eq "clipboard:paste") {
|
|
$self->paste;
|
|
} elsif ($cmd eq "clipboard:paste_escaped") {
|
|
$self->paste_escaped;
|
|
}
|
|
|
|
()
|
|
}
|