urxvt-perls/clipboard

66 lines
1.3 KiB
Plaintext
Raw Normal View History

#! 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;
sub copy {
2010-08-02 18:39:34 -04:00
my ($self) = @_;
open(CLIPBOARD, "| xsel -ib");
2010-08-02 18:39:34 -04:00
my $sel = $self->selection();
utf8::encode($sel);
print CLIPBOARD $sel;
close(CLIPBOARD);
()
}
sub paste {
2010-08-02 18:39:34 -04:00
my ($self) = @_;
my $str = `xsel -ob`;
$str =~ tr/\n/\r/;
2010-08-02 18:39:34 -04:00
$self->tt_write($str);
()
}
sub paste_escaped {
2010-08-02 18:39:34 -04:00
my ($self) = @_;
my $str = `xsel -ob`;
$str =~ tr/\n/\r/;
$str =~ s/([!#\$%&\*\(\) ='"\\\|\[\]`~,<>\?])/\\\1/g;
2010-08-02 18:39:34 -04:00
$self->tt_write($str);
()
}
sub on_user_command {
2010-08-02 18:39:34 -04:00
my ($self, $cmd) = @_;
if ($cmd eq "clipboard:copy") {
2010-08-02 18:39:34 -04:00
$self->copy;
} elsif ($cmd eq "clipboard:paste") {
2010-08-02 18:39:34 -04:00
$self->paste;
} elsif ($cmd eq "clipboard:paste_escaped") {
2010-08-02 18:39:34 -04:00
$self->paste_escaped;
}
()
}