aboutsummaryrefslogtreecommitdiff
path: root/urxvt/ext
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2014-04-27 00:44:47 +1200
committerTom Ryder <tom@sanctum.geek.nz>2014-04-27 00:44:47 +1200
commit72bac26a22373fe0ebed377cd5229dbbc8286996 (patch)
treea2effd51c9668f4a77448f6992846edcb22d8d21 /urxvt/ext
parent71b48c99f1cccf4b3dc7144fa894d48ba4c5e497 (diff)
downloaddotfiles-72bac26a22373fe0ebed377cd5229dbbc8286996.tar.gz
dotfiles-72bac26a22373fe0ebed377cd5229dbbc8286996.zip
Tidier Perl for custom clip script
Diffstat (limited to 'urxvt/ext')
-rw-r--r--urxvt/ext/clip18
1 files changed, 12 insertions, 6 deletions
diff --git a/urxvt/ext/clip b/urxvt/ext/clip
index 4f890c0e..b09eadfe 100644
--- a/urxvt/ext/clip
+++ b/urxvt/ext/clip
@@ -5,6 +5,10 @@
use strict;
use warnings;
+use Carp;
+
+our $VERSION = 1.0;
+
sub on_start {
my ($self) = @_;
$self->enable( sel_grab => \&clip );
@@ -13,12 +17,14 @@ sub on_start {
sub clip {
my ($self) = @_;
- if ( open CLIPBOARD, '| xsel -ib' ) {
- my $sel = $self->selection();
- utf8::encode($sel);
- print CLIPBOARD $sel;
- close CLIPBOARD;
- }
+ my $selection = $self->selection();
+ utf8::encode($selection);
+ open my $clipboard, q{|-}, 'xsel -ib'
+ or croak('xsel(1) not available');
+ print {$clipboard} $selection
+ or croak('Failed to write to xsel(1) pipe');
+ close $clipboard
+ or croak('Failed to close xsel(1) pipe');
return;
}