ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/perl/clipboard
(Generate patch)

Comparing rxvt-unicode/src/perl/clipboard (file contents):
Revision 1.3 by sf-exg, Tue Jan 28 20:34:25 2014 UTC vs.
Revision 1.4 by root, Sun Apr 13 08:56:12 2014 UTC

1#! perl -w 1#! perl -w
2
3#:META:X_RESOURCE:%.copycmd:string:command expecting clip data on stdin
4#:META:X_RESOURCE:%.pastecmd:string:command that writes clip data to stdout
5#undocumented/deprecated #:META:X_RESOURCE:%.paste_escaped:boolean:
6#:META:X_RESOURCE:%.autcopy:boolean:automatically copy on selection grab
7
2# Author: Bert Muennich 8# Author: Bert Muennich
3# Website: http://www.github.com/muennich/urxvt-perls 9# Website: http://www.github.com/muennich/urxvt-perls
4# License: GPLv2 10# License: GPLv2
5 11
6# Use keyboard shortcuts to copy the selection to the clipboard and to paste 12# Use keyboard shortcuts to copy the selection to the clipboard and to paste
32use strict; 38use strict;
33 39
34sub on_start { 40sub on_start {
35 my ($self) = @_; 41 my ($self) = @_;
36 42
37 $self->{copy_cmd} = $self->x_resource('clipboard.copycmd') || 'xsel -ib'; 43 $self->{copy_cmd} = $self->x_resource ('%.copycmd' ) || 'xsel -ib';
38 $self->{paste_cmd} = $self->x_resource('clipboard.pastecmd') || 'xsel -ob'; 44 $self->{paste_cmd} = $self->x_resource ('%.pastecmd') || 'xsel -ob';
39 45
40 if ($self->x_resource('clipboard.autocopy') eq 'true') { 46 if ($self->x_resource_boolean ('%.autocopy')) {
41 $self->enable(sel_grab => \&sel_grab); 47 $self->enable (sel_grab => \&sel_grab);
42 } 48 }
43 49
44 () 50 ()
45} 51}
46 52
47sub copy { 53sub copy {
48 my ($self) = @_; 54 my ($self) = @_;
49 55
50 if (open(CLIPBOARD, "| $self->{copy_cmd}")) { 56 if (open my $fh, "| $self->{copy_cmd}") {
51 my $sel = $self->selection(); 57 my $sel = $self->selection;
52 $sel = $self->locale_encode ($sel); 58 $sel = $self->locale_encode ($sel);
53 print CLIPBOARD $sel; 59 syswrite $fh, $sel;
54 close(CLIPBOARD);
55 } else { 60 } else {
56 print STDERR "error running '$self->{copy_cmd}': $!\n"; 61 print STDERR "error running '$self->{copy_cmd}': $!\n";
57 } 62 }
58 63
59 () 64 ()
60} 65}
61 66
62sub paste { 67sub paste {
63 my ($self, $escape) = @_; 68 my ($self, $escape) = @_;
64 69
65 my $str = `$self->{paste_cmd}`; 70 my $str = qx<$self->{paste_cmd}>;
71
66 if ($? == 0) { 72 if ($? == 0) {
67 $str =~ s/([!#\$%&\*\(\) ='"\\\|\[\]`~,<>\?])/\\\1/g 73 $str =~ s/([!#\$%&\*\(\) ='"\\\|\[\]`~,<>\?])/\\\1/g
68 if ($escape); 74 if $escape;
75
69 $self->tt_paste($str); 76 $self->tt_paste ($str);
70 } else { 77 } else {
71 print STDERR "error running '$self->{paste_cmd}': $!\n"; 78 print STDERR "error running '$self->{paste_cmd}': $!\n";
72 } 79 }
73 80
74 () 81 ()
93 100
94 $self->copy; 101 $self->copy;
95 102
96 () 103 ()
97} 104}
105

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines