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 | |
5 | |
7 | sub upload_paste { |
6 | sub upload_paste { |
8 | my ($self) = @_; |
7 | my ($self) = @_; |
… | |
… | |
14 | |
13 | |
15 | my $tmpfile = "/tmp/$filename"; |
14 | my $tmpfile = "/tmp/$filename"; |
16 | |
15 | |
17 | my $msg = "uploaded $filename"; |
16 | my $msg = "uploaded $filename"; |
18 | |
17 | |
19 | if (open my $o, ">" . $tmpfile) { |
18 | if (open my $o, ">", $tmpfile) { |
|
|
19 | chmod 0644, $tmpfile; |
20 | print $o $txt; |
20 | print $o $txt; |
21 | close $o; |
21 | close $o; |
22 | } else { |
22 | } else { |
23 | $msg = "couldn't write $tmpfile: $!"; |
23 | $msg = "couldn't write $tmpfile: $!"; |
24 | } |
24 | } |
… | |
… | |
35 | $msg = "couldn't upload, '$cmd' failed"; |
35 | $msg = "couldn't upload, '$cmd' failed"; |
36 | } |
36 | } |
37 | |
37 | |
38 | unlink $tmpfile; |
38 | unlink $tmpfile; |
39 | |
39 | |
40 | 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); |
41 | $ov->set (0, 0, $msg); |
41 | $ov->set (0, 0, $msg); |
42 | |
42 | |
43 | $timers->{t1} = |
43 | my $timer; $timer = |
44 | urxvt::timer |
44 | urxvt::timer |
45 | ->new |
45 | ->new |
46 | ->start ((int urxvt::NOW) + 5) # make sure we update "on" the second |
|
|
47 | ->interval (1) |
46 | ->after (5) |
48 | ->cb (sub { delete $timers->{ov}; delete $timers->{t1}; }); |
47 | ->cb (sub {undef $timer; undef $ov; }); |
49 | } |
48 | } |
50 | |
49 | |
51 | sub on_start { |
50 | sub on_start { |
52 | my ($self) = @_; |
51 | my ($self) = @_; |
53 | $pastebin_cmd = $self->x_resource ("selection-pastebin.cmd") |
52 | $pastebin_cmd = $self->x_resource ("selection-pastebin.cmd") |
54 | || "scp -p % ruth:/var/www/www.ta-sa.org/files/txt/"; |
53 | || "rcp -p % ruth:/var/www/www.ta-sa.org/files/txt/"; |
55 | |
54 | |
56 | $pastebin_url = $self->x_resource ("selection-pastebin.url") |
55 | $pastebin_url = $self->x_resource ("selection-pastebin.url") |
57 | || "http://www.ta-sa.org/files/txt/%"; |
56 | || "http://www.ta-sa.org/files/txt/%"; |
58 | |
57 | |
59 | push @urxvt::ext::selection_popup::hook, sub { |
|
|
60 | ("pastebin upload" => sub { $self->upload_paste }) |
|
|
61 | }; |
|
|
62 | |
|
|
63 | () |
58 | () |
64 | } |
59 | } |
|
|
60 | |
|
|
61 | push @urxvt::ext::selection_popup::hook, sub { |
|
|
62 | ("pastebin upload" => sub { $self->upload_paste }) |
|
|
63 | }; |
65 | |
64 | |
66 | sub on_keyboard_command { |
65 | sub on_keyboard_command { |
67 | my ($self, $cmd) = @_; |
66 | my ($self, $cmd) = @_; |
68 | |
67 | |
69 | if ($cmd eq "selection-pastebin:remote-pastebin") { |
68 | if ($cmd eq "selection-pastebin:remote-pastebin") { |