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.13 by root, Mon Jan 23 23:13:03 2006 UTC vs.
Revision 1.14 by root, Wed Jan 25 14:53:14 2006 UTC

1#! perl 1#! perl
2
3my $pastebin_cmd;
4my $pastebin_url;
5 2
6sub upload_paste { 3sub upload_paste {
7 my ($self) = @_; 4 my ($self) = @_;
8 5
9 require Digest::MD5; 6 require Digest::MD5;
13 10
14 my $tmpfile = "/tmp/$filename"; 11 my $tmpfile = "/tmp/$filename";
15 12
16 my $msg = "uploaded as $filename"; 13 my $msg = "uploaded as $filename";
17 14
18 if (open my $o, ">:utf-8", $tmpfile) { 15 if (open my $o, ">:utf8", $tmpfile) {
19 chmod 0644, $tmpfile; 16 chmod 0644, $tmpfile;
20 print $o $txt; 17 print $o $txt;
21 close $o; 18 close $o;
22 } else { 19 } else {
23 $msg = "couldn't write $tmpfile: $!"; 20 $msg = "couldn't write $tmpfile: $!";
24 } 21 }
25 22
26 my $cmd = $pastebin_cmd; 23 my $cmd = $self->{pastebin_cmd};
27 $cmd =~ s/%/$tmpfile/; 24 $cmd =~ s/%/$tmpfile/;
28 25
29 if (system ($cmd) == 0) { 26 my $pid = $self->exec_async ("/bin/sh", "-c", $cmd);
30 my $url = $pastebin_url;
31 $url =~ s/%/$filename/;
32 27
33 $self->selection ($url); 28 $self->{pw} = urxvt::pw->new->start ($pid)->cb (sub {
34 } else { 29 my (undef, $status) = @_;
35 $msg = "couldn't upload, '$cmd' failed";
36 }
37 30
38 unlink $tmpfile; 31 delete $self->{pw};
39 32
40 my $ov = $self->overlay (-1, 0, length $msg, 1, urxvt::OVERLAY_RSTYLE, 0); 33 if ($status) {
41 $ov->set (0, 0, $msg); 34 $status >>= 8;
35 $msg = "ERROR: command returned status $status";
36 } else {
37 my $url = $self->{pastebin_url};
38 $url =~ s/%/$filename/;
42 39
43 my $timer; $timer = 40 $self->selection ($url);
41 }
42
43 unlink $tmpfile;
44
45 my $ov = $self->overlay (-1, 0, $self->strwidth ($msg), 1, urxvt::OVERLAY_RSTYLE, 0);
46 $ov->set (0, 0, $msg);
47
48 $self->{timer} =
44 urxvt::timer 49 urxvt::timer
45 ->new 50 ->new
46 ->after (5) 51 ->after (5)
47 ->cb (sub { undef $timer; undef $ov; }); 52 ->cb (sub { delete $self->{timer}; undef $ov; });
53 });
48} 54}
49 55
50sub on_start { 56sub on_start {
51 my ($self) = @_; 57 my ($self) = @_;
52 58
53 $pastebin_cmd = $self->x_resource ("selection-pastebin.cmd") 59 $self->{pastebin_cmd} = $self->x_resource ("selection-pastebin.cmd")
54 || "rcp -p % ruth:/var/www/www.ta-sa.org/files/txt/"; 60 || "rcp -p % ruth:/var/www/www.ta-sa.org/files/txt/";
55 61
56 $pastebin_url = $self->x_resource ("selection-pastebin.url") 62 $self->{pastebin_url} = $self->x_resource ("selection-pastebin.url")
57 || "http://www.ta-sa.org/files/txt/%"; 63 || "http://www.ta-sa.org/files/txt/%";
58 64
59 push @{ $self->{term}{selection_popup_hook} }, sub { 65 push @{ $self->{term}{selection_popup_hook} }, sub {
60 ("pastebin upload" => sub { $self->upload_paste }) 66 ("pastebin upload" => sub { $self->upload_paste })
61 }; 67 };
62 68

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines