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.6 by root, Wed Jan 18 10:31:37 2006 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines