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