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.3 by root, Tue Jan 17 17:01:54 2006 UTC vs.
Revision 1.6 by root, Wed Jan 18 10:31:37 2006 UTC

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