ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/perl/clipboard
Revision: 1.5
Committed: Sun Apr 13 10:47:14 2014 UTC (10 years, 1 month ago) by sf-exg
Branch: MAIN
CVS Tags: HEAD
Changes since 1.4: +0 -0 lines
State: FILE REMOVED
Log Message:
Revert addition of clipboard perl extension.

File Contents

# Content
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
8 # Author: Bert Muennich
9 # Website: http://www.github.com/muennich/urxvt-perls
10 # License: GPLv2
11
12 # Use keyboard shortcuts to copy the selection to the clipboard and to paste
13 # the clipboard contents (optionally escaping all special characters).
14 # Requires xsel to be installed!
15
16 # Usage: put the following lines in your .Xdefaults/.Xresources:
17 # URxvt.perl-ext-common: ...,clipboard
18 # URxvt.keysym.M-c: perl:clipboard:copy
19 # URxvt.keysym.M-v: perl:clipboard:paste
20 # URxvt.keysym.M-C-v: perl:clipboard:paste_escaped
21
22 # Options:
23 # URxvt.clipboard.autocopy: If true, PRIMARY overwrites clipboard
24
25 # You can also overwrite the system commands to use for copying/pasting.
26 # The default ones are:
27 # URxvt.clipboard.copycmd: xsel -ib
28 # URxvt.clipboard.pastecmd: xsel -ob
29 # If you prefer xclip, then put these lines in your .Xdefaults/.Xresources:
30 # URxvt.clipboard.copycmd: xclip -i -selection clipboard
31 # URxvt.clipboard.pastecmd: xclip -o -selection clipboard
32 # On Mac OS X, put these lines in your .Xdefaults/.Xresources:
33 # URxvt.clipboard.copycmd: pbcopy
34 # URxvt.clipboard.pastecmd: pbpaste
35
36 # The use of the functions should be self-explanatory!
37
38 use strict;
39
40 sub on_start {
41 my ($self) = @_;
42
43 $self->{copy_cmd} = $self->x_resource ('%.copycmd' ) || 'xsel -ib';
44 $self->{paste_cmd} = $self->x_resource ('%.pastecmd') || 'xsel -ob';
45
46 if ($self->x_resource_boolean ('%.autocopy')) {
47 $self->enable (sel_grab => \&sel_grab);
48 }
49
50 ()
51 }
52
53 sub copy {
54 my ($self) = @_;
55
56 if (open my $fh, "| $self->{copy_cmd}") {
57 my $sel = $self->selection;
58 $sel = $self->locale_encode ($sel);
59 syswrite $fh, $sel;
60 } else {
61 print STDERR "error running '$self->{copy_cmd}': $!\n";
62 }
63
64 ()
65 }
66
67 sub paste {
68 my ($self, $escape) = @_;
69
70 my $str = qx<$self->{paste_cmd}>;
71
72 if ($? == 0) {
73 $str =~ s/([!#\$%&\*\(\) ='"\\\|\[\]`~,<>\?])/\\\1/g
74 if $escape;
75
76 $self->tt_paste ($str);
77 } else {
78 print STDERR "error running '$self->{paste_cmd}': $!\n";
79 }
80
81 ()
82 }
83
84 sub on_user_command {
85 my ($self, $cmd) = @_;
86
87 if ($cmd eq "clipboard:copy") {
88 $self->copy;
89 } elsif ($cmd eq "clipboard:paste") {
90 $self->paste (0);
91 } elsif ($cmd eq "clipboard:paste_escaped") {
92 $self->paste (1);
93 }
94
95 ()
96 }
97
98 sub sel_grab {
99 my ($self) = @_;
100
101 $self->copy;
102
103 ()
104 }
105