1 | #! perl |
1 | #! perl |
2 | use Digest::MD5 qw/md5_hex/; |
|
|
3 | |
2 | |
4 | my $timers = {}; |
3 | my $timers = {}; |
5 | my $pastebin_cmd; |
4 | my $pastebin_cmd; |
6 | my $pastebin_url; |
5 | my $pastebin_url; |
7 | |
6 | |
8 | sub 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 | |
|
|
20 | sub upload_paste { |
7 | sub 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 | |
… | |
… | |
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 = $timers->{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 | $timers->{t1} = |
54 | urxvt::timer |
44 | urxvt::timer |
… | |
… | |
56 | ->start ((int urxvt::NOW) + 5) # make sure we update "on" the second |
46 | ->start ((int urxvt::NOW) + 5) # make sure we update "on" the second |
57 | ->interval (1) |
47 | ->interval (1) |
58 | ->cb (sub { delete $timers->{ov}; delete $timers->{t1}; }); |
48 | ->cb (sub { delete $timers->{ov}; delete $timers->{t1}; }); |
59 | } |
49 | } |
60 | |
50 | |
61 | sub on_keyboard_command { |
51 | sub on_start { |
62 | my ($self, $cmd) = @_; |
52 | my ($self) = @_; |
|
|
53 | $pastebin_cmd = $self->x_resource ("selection-pastebin.cmd") |
|
|
54 | || "scp -p % ruth:/var/www/www.ta-sa.org/files/txt/"; |
63 | |
55 | |
64 | $cmd eq "selection-pastebin:remote-pastebin" |
56 | $pastebin_url = $self->x_resource ("selection-pastebin.url") |
65 | and upload_paste ($self); |
57 | || "http://www.ta-sa.org/files/txt/%"; |
|
|
58 | |
|
|
59 | push @urxvt::ext::selection_popup::hook, sub { |
|
|
60 | ("pastebin upload" => sub { $self->upload_paste }) |
|
|
61 | }; |
66 | |
62 | |
67 | () |
63 | () |
68 | } |
64 | } |
69 | |
65 | |
|
|
66 | sub on_keyboard_command { |
|
|
67 | my ($self, $cmd) = @_; |
|
|
68 | |
|
|
69 | if ($cmd eq "selection-pastebin:remote-pastebin") { |
|
|
70 | $self->upload_paste; |
|
|
71 | } |
|
|
72 | |
|
|
73 | () |
|
|
74 | } |
|
|
75 | |