xclip-board -> clipboard, using xsel instead of xclip

This commit is contained in:
Bert 2010-08-02 16:34:16 +02:00
parent bb677ec9de
commit 33024bb68c
2 changed files with 66 additions and 66 deletions

66
clipboard Normal file
View File

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

View File

@ -1,66 +0,0 @@
#! 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 xclip to be installed!
# Usage: put the following lines in your .Xdefaults:
# URxvt.perl-ext-common: xclip-board
# URxvt.keysym.M-c: perl:xclip-board:copy
# URxvt.keysym.M-v: perl:xclip-board:paste
# URxvt.keysym.M-C-v: perl:xclip-board:paste_escaped
# The use of the functions should be self-explanatory!
use strict;
use utf8;
sub copy {
my ($self) = @_;
open(CLIPBOARD, "| xclip -i -selection clipboard");
my $sel = $self->selection;
utf8::encode($sel);
print CLIPBOARD $sel;
close(CLIPBOARD);
()
}
sub paste {
my ($self) = @_;
my $str = `xclip -o -selection clipboard`;
$str =~ tr/\n/\r/;
$self->tt_write($str);
()
}
sub paste_escaped {
my ($self) = @_;
my $str = `xclip -o -selection clipboard`;
$str =~ tr/\n/\r/;
$str =~ s/([!#\$%&\*\(\) ='"\\\|\[\]`~,<>\?])/\\\1/g;
$self->tt_write($str);
()
}
sub on_user_command {
my ($self, $cmd) = @_;
if ($cmd eq "xclip-board:copy") {
$self->copy;
} elsif ($cmd eq "xclip-board:paste") {
$self->paste;
} elsif ($cmd eq "xclip-board:paste_escaped") {
$self->paste_escaped;
}
()
}