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.1 by elmex, Tue Jan 17 16:53:47 2006 UTC vs.
Revision 1.8 by root, Wed Jan 18 11:05:09 2006 UTC

1#! perl 1#! perl
2use Digest::MD5 qw/md5_hex/;
3 2
4my $timers = {};
5my $pastebin_cmd; 3my $pastebin_cmd;
6my $pastebin_url; 4my $pastebin_url;
7
8sub on_start {
9 my ($self) = @_;
10 $pastebin_cmd =
11 $self->x_resource ("selection-pastebin-cmd")
12 or "scp -p % ruth:/var/www/www.ta-sa.org/files/txt/";
13
14 $pastebin_url =
15 $self->x_resource ("selection-pastebin-url")
16 or "http://www.ta-sa.org/files/txt/";
17 ();
18}
19 5
20sub upload_paste { 6sub upload_paste {
21 my ($self) = @_; 7 my ($self) = @_;
22 8
9 require Digest::MD5;
23 10
24 my $txt = $self->selection; 11 my $txt = $self->selection;
25 my $filename = md5_hex ($txt) . ".txt"; 12 my $filename = Digest::MD5::md5_hex ($txt) . ".txt";
26 13
27 my $tmpfile = "/tmp/$filename"; 14 my $tmpfile = "/tmp/$filename";
28 15
29 my $msg = "uploaded $filename"; 16 my $msg = "uploaded $filename";
30 17
31 if (open my $o, ">" . $tmpfile) { 18 if (open my $o, ">", $tmpfile) {
19 chmod 0644, $tmpfile;
32 print $o $txt; 20 print $o $txt;
33 close $o; 21 close $o;
34 } else { 22 } else {
35 $msg = "couldn't write $tmpfile: $!"; 23 $msg = "couldn't write $tmpfile: $!";
36 } 24 }
45 $self->selection ($url); 33 $self->selection ($url);
46 } else { 34 } else {
47 $msg = "couldn't upload, '$cmd' failed"; 35 $msg = "couldn't upload, '$cmd' failed";
48 } 36 }
49 37
38 unlink $tmpfile;
39
50 my $ov = $timers->{ov} = $self->overlay (-1, 0, length ($msg), 1, urxvt::OVERLAY_RSTYLE, 0); 40 my $ov = $self->overlay (-1, 0, length $msg, 1, urxvt::OVERLAY_RSTYLE, 0);
51 $ov->set (0, 0, $msg); 41 $ov->set (0, 0, $msg);
52 42
53 $timers->{t1} = 43 my $timer; $timer =
54 urxvt::timer 44 urxvt::timer
55 ->new 45 ->new
56 ->start ((int urxvt::NOW) + 5) # make sure we update "on" the second
57 ->interval (1) 46 ->after (5)
58 ->cb (sub { delete $timers->{ov}; delete $timers->{t1}; }); 47 ->cb (sub {undef $timer; undef $ov; });
48}
49
50sub on_start {
51 my ($self) = @_;
52 $pastebin_cmd = $self->x_resource ("selection-pastebin.cmd")
53 || "rcp -p % ruth:/var/www/www.ta-sa.org/files/txt/";
54
55 $pastebin_url = $self->x_resource ("selection-pastebin.url")
56 || "http://www.ta-sa.org/files/txt/%";
57
58 push @urxvt::ext::selection_popup::hook, sub {
59 ("pastebin upload" => sub { $self->upload_paste })
60 };
61
62 ()
59} 63}
60 64
61sub on_keyboard_command { 65sub on_keyboard_command {
62 my ($self, $cmd) = @_; 66 my ($self, $cmd) = @_;
63 67
64 $cmd eq "selection-pastebin:remote-pastebin" 68 if ($cmd eq "selection-pastebin:remote-pastebin") {
65 and upload_paste ($self); 69 $self->upload_paste;
70 }
66 71
67 () 72 ()
68} 73}
69 74

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines