clipboard: allow user to overwrite copy/paste commands

This commit is contained in:
Bert 2011-05-28 12:50:52 +02:00
parent 5c22ddc57c
commit 78cf641878
2 changed files with 42 additions and 8 deletions

View File

@ -71,8 +71,6 @@ clipboard
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!
After installing, put the following lines in your .Xdefaults:
URxvt.perl-ext-common: ...,clipboard
@ -80,4 +78,20 @@ After installing, put the following lines in your .Xdefaults:
URxvt.keysym.M-v: perl:clipboard:paste
URxvt.keysym.M-C-v: perl:clipboard:paste_escaped
You can also overwrite the system commands to use for copying/pasting.
The default ones are:
URxvt.copyCommand: xsel -ib
URxvt.pasteCommand: xsel -ob
If you prefer xclip, then put these lines in your .Xdefaults:
URxvt.copyCommand: xclip -i -selection clipboard
URxvt.pasteCommand: xclip -o -selection clipboard
On Mac OS X, put these lines in your .Xdefaults:
URxvt.copyCommand: pbcopy
URxvt.pasteCommand: pbpaste
The use of the functions should be self-explanatory!

View File

@ -13,20 +13,40 @@
# URxvt.keysym.M-v: perl:clipboard:paste
# URxvt.keysym.M-C-v: perl:clipboard:paste_escaped
# You can also overwrite the system commands to use for copying/pasting.
# The default ones are:
# URxvt.copyCommand: xsel -ib
# URxvt.pasteCommand: xsel -ob
# If you prefer xclip, then put these lines in your .Xdefaults:
# URxvt.copyCommand: xclip -i -selection clipboard
# URxvt.pasteCommand: xclip -o -selection clipboard
# On Mac OS X, put these lines in your .Xdefaults:
# URxvt.copyCommand: pbcopy
# URxvt.pasteCommand: pbpaste
# The use of the functions should be self-explanatory!
use strict;
sub on_start {
my ($self) = @_;
$self->{copy_cmd} = $self->x_resource('copyCommand') || 'xsel -ib';
$self->{paste_cmd} = $self->x_resource('pasteCommand') || 'xsel -ob';
()
}
sub copy {
my ($self) = @_;
if (open(CLIPBOARD, "| xsel -ib")) {
if (open(CLIPBOARD, "| $self->{copy_cmd}")) {
my $sel = $self->selection();
utf8::encode($sel);
print CLIPBOARD $sel;
close(CLIPBOARD);
} else {
print STDERR "Error running xsel: $!\n";
print STDERR "error running '$self->{copy_cmd}': $!\n";
}
()
@ -35,11 +55,11 @@ sub copy {
sub paste {
my ($self) = @_;
my $str = `xsel -ob`;
my $str = `$self->{paste_cmd}`;
if ($? == 0) {
$self->tt_paste($self->locale_encode($str));
} else {
print STDERR "Error running xsel: $!\n";
print STDERR "error running '$self->{paste_cmd}': $!\n";
}
()
@ -48,12 +68,12 @@ sub paste {
sub paste_escaped {
my ($self) = @_;
my $str = `xsel -ob`;
my $str = `$self->{paste_cmd}`;
if ($? == 0) {
$str =~ s/([!#\$%&\*\(\) ='"\\\|\[\]`~,<>\?])/\\\1/g;
$self->tt_paste($self->locale_encode($str));
} else {
print STDERR "Error running xsel: $!\n";
print STDERR "error running '$self->{paste_cmd}': $!\n";
}
()