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

Comparing rxvt-unicode/src/perl/selection-pastebin (file contents):
Revision 1.16 by root, Fri Mar 10 21:36:16 2006 UTC vs.
Revision 1.21 by root, Sun Jun 10 17:39:54 2012 UTC

1#! perl 1#! perl
2
3#:META:X_RESOURCE:%.cmd:string:the command to run create a new pastebin
4#:META:X_RESOURCE:%.url:string:the url template for new pastebins
5
6=head1 NAME
7
8 selection-pastebin - automatic pastebin upload
9
10=head1 DESCRIPTION
11
12This is a little rarely useful extension that uploads the selection as
13textfile to a remote site (or does other things). (The implementation is
14not currently secure for use in a multiuser environment as it writes to
15F</tmp> directly.).
16
17It listens to the C<selection-pastebin:remote-pastebin> keyboard command,
18i.e.
19
20 URxvt.keysym.C-M-e: perl:selection-pastebin:remote-pastebin
21
22Pressing this combination runs a command with C<%> replaced by the name of
23the textfile. This command can be set via a resource:
24
25 URxvt.selection-pastebin.cmd: rsync -apP % ruth:/var/www/www.ta-sa.org/files/txt/.
26
27And the default is likely not useful to anybody but the few people around
28here :)
29
30The name of the textfile is the hex encoded md5 sum of the selection, so
31the same content should lead to the same filename.
32
33After a successful upload the selection will be replaced by the text given
34in the C<selection-pastebin-url> resource (again, the % is the placeholder
35for the filename):
36
37 URxvt.selection-pastebin.url: http://www.ta-sa.org/files/txt/%
38
39I<Note to xrdb users:> xrdb uses the C preprocessor, which might interpret
40the double C</> characters as comment start. Use C<\057\057> instead,
41which works regardless of whether xrdb is used to parse the resource file
42or not.
43
44=cut
2 45
3sub upload_paste { 46sub upload_paste {
4 my ($self) = @_; 47 my ($self) = @_;
5 48
6 require Digest::MD5; 49 require Digest::MD5;
24 } 67 }
25 68
26 my $cmd = $self->{pastebin_cmd}; 69 my $cmd = $self->{pastebin_cmd};
27 $cmd =~ s/%/$tmpfile/; 70 $cmd =~ s/%/$tmpfile/;
28 71
29 my $pid = $self->exec_async ("/bin/sh", "-c", $cmd); 72 my $pid = $self->exec_async ($cmd);
30 73
31 $self->{pw} = urxvt::pw->new->start ($pid)->cb (sub { 74 $self->{pw} = urxvt::pw->new->start ($pid)->cb (sub {
32 my (undef, $status) = @_; 75 my (undef, $status) = @_;
33 76
34 delete $self->{pw}; 77 delete $self->{pw};
57} 100}
58 101
59sub on_start { 102sub on_start {
60 my ($self) = @_; 103 my ($self) = @_;
61 104
62 $self->{pastebin_cmd} = $self->x_resource ("selection-pastebin.cmd") 105 $self->{pastebin_cmd} = $self->x_resource ("%.cmd")
63 || "rcp -p % ruth:/var/www/www.ta-sa.org/files/txt/"; 106 || "rcp -p % ruth:/var/www/www.ta-sa.org/files/txt/";
64 107
65 $self->{pastebin_url} = $self->x_resource ("selection-pastebin.url") 108 $self->{pastebin_url} = $self->x_resource ("%.url")
66 || "http://www.ta-sa.org/files/txt/%"; 109 || "http://www.ta-sa.org/files/txt/%";
67 110
68 push @{ $self->{term}{selection_popup_hook} }, sub { 111 push @{ $self->{term}{selection_popup_hook} }, sub {
69 ("pastebin upload" => sub { $self->upload_paste }) 112 ("pastebin upload" => sub { $self->upload_paste })
70 }; 113 };

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines