clipboard: allow user to overwrite copy/paste commands
This commit is contained in:
parent
5c22ddc57c
commit
78cf641878
18
README.md
18
README.md
@ -71,8 +71,6 @@ clipboard
|
|||||||
Use keyboard shortcuts to copy the selection to the clipboard and to paste the
|
Use keyboard shortcuts to copy the selection to the clipboard and to paste the
|
||||||
clipboard contents (optionally escaping all special characters).
|
clipboard contents (optionally escaping all special characters).
|
||||||
|
|
||||||
Requires xsel to be installed!
|
|
||||||
|
|
||||||
After installing, put the following lines in your .Xdefaults:
|
After installing, put the following lines in your .Xdefaults:
|
||||||
|
|
||||||
URxvt.perl-ext-common: ...,clipboard
|
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-v: perl:clipboard:paste
|
||||||
URxvt.keysym.M-C-v: perl:clipboard:paste_escaped
|
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!
|
The use of the functions should be self-explanatory!
|
||||||
|
32
clipboard
32
clipboard
@ -13,20 +13,40 @@
|
|||||||
# URxvt.keysym.M-v: perl:clipboard:paste
|
# URxvt.keysym.M-v: perl:clipboard:paste
|
||||||
# URxvt.keysym.M-C-v: perl:clipboard:paste_escaped
|
# 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!
|
# The use of the functions should be self-explanatory!
|
||||||
|
|
||||||
use strict;
|
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 {
|
sub copy {
|
||||||
my ($self) = @_;
|
my ($self) = @_;
|
||||||
|
|
||||||
if (open(CLIPBOARD, "| xsel -ib")) {
|
if (open(CLIPBOARD, "| $self->{copy_cmd}")) {
|
||||||
my $sel = $self->selection();
|
my $sel = $self->selection();
|
||||||
utf8::encode($sel);
|
utf8::encode($sel);
|
||||||
print CLIPBOARD $sel;
|
print CLIPBOARD $sel;
|
||||||
close(CLIPBOARD);
|
close(CLIPBOARD);
|
||||||
} else {
|
} else {
|
||||||
print STDERR "Error running xsel: $!\n";
|
print STDERR "error running '$self->{copy_cmd}': $!\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
()
|
()
|
||||||
@ -35,11 +55,11 @@ sub copy {
|
|||||||
sub paste {
|
sub paste {
|
||||||
my ($self) = @_;
|
my ($self) = @_;
|
||||||
|
|
||||||
my $str = `xsel -ob`;
|
my $str = `$self->{paste_cmd}`;
|
||||||
if ($? == 0) {
|
if ($? == 0) {
|
||||||
$self->tt_paste($self->locale_encode($str));
|
$self->tt_paste($self->locale_encode($str));
|
||||||
} else {
|
} else {
|
||||||
print STDERR "Error running xsel: $!\n";
|
print STDERR "error running '$self->{paste_cmd}': $!\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
()
|
()
|
||||||
@ -48,12 +68,12 @@ sub paste {
|
|||||||
sub paste_escaped {
|
sub paste_escaped {
|
||||||
my ($self) = @_;
|
my ($self) = @_;
|
||||||
|
|
||||||
my $str = `xsel -ob`;
|
my $str = `$self->{paste_cmd}`;
|
||||||
if ($? == 0) {
|
if ($? == 0) {
|
||||||
$str =~ s/([!#\$%&\*\(\) ='"\\\|\[\]`~,<>\?])/\\\1/g;
|
$str =~ s/([!#\$%&\*\(\) ='"\\\|\[\]`~,<>\?])/\\\1/g;
|
||||||
$self->tt_paste($self->locale_encode($str));
|
$self->tt_paste($self->locale_encode($str));
|
||||||
} else {
|
} else {
|
||||||
print STDERR "Error running xsel: $!\n";
|
print STDERR "error running '$self->{paste_cmd}': $!\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
()
|
()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user