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 { |
7 | sub on_start { |
9 | my ($self) = @_; |
8 | my ($self) = @_; |
10 | $pastebin_cmd = |
9 | $pastebin_cmd = |
11 | $self->x_resource ("selection-pastebin-cmd") |
10 | $self->x_resource ("selection-pastebin.cmd") |
12 | or "scp -p % ruth:/var/www/www.ta-sa.org/files/txt/"; |
11 | or "scp -p % ruth:/var/www/www.ta-sa.org/files/txt/"; |
13 | |
12 | |
14 | $pastebin_url = |
13 | $pastebin_url = |
15 | $self->x_resource ("selection-pastebin-url") |
14 | $self->x_resource ("selection-pastebin.url") |
16 | or "http://www.ta-sa.org/files/txt/"; |
15 | or "http://www.ta-sa.org/files/txt/"; |
|
|
16 | |
17 | (); |
17 | () |
18 | } |
18 | } |
19 | |
19 | |
20 | sub upload_paste { |
20 | sub upload_paste { |
21 | my ($self) = @_; |
21 | my ($self) = @_; |
22 | |
22 | |
|
|
23 | require Digest::MD5; |
23 | |
24 | |
24 | my $txt = $self->selection; |
25 | my $txt = $self->selection; |
25 | my $filename = md5_hex ($txt) . ".txt"; |
26 | my $filename = Digest::MD5::md5_hex ($txt) . ".txt"; |
26 | |
27 | |
27 | my $tmpfile = "/tmp/$filename"; |
28 | my $tmpfile = "/tmp/$filename"; |
28 | |
29 | |
29 | my $msg = "uploaded $filename"; |
30 | my $msg = "uploaded $filename"; |
30 | |
31 | |
… | |
… | |
45 | $self->selection ($url); |
46 | $self->selection ($url); |
46 | } else { |
47 | } else { |
47 | $msg = "couldn't upload, '$cmd' failed"; |
48 | $msg = "couldn't upload, '$cmd' failed"; |
48 | } |
49 | } |
49 | |
50 | |
|
|
51 | unlink $tmpfile; |
|
|
52 | |
50 | my $ov = $timers->{ov} = $self->overlay (-1, 0, length ($msg), 1, urxvt::OVERLAY_RSTYLE, 0); |
53 | my $ov = $timers->{ov} = $self->overlay (-1, 0, length ($msg), 1, urxvt::OVERLAY_RSTYLE, 0); |
51 | $ov->set (0, 0, $msg); |
54 | $ov->set (0, 0, $msg); |
52 | |
55 | |
53 | $timers->{t1} = |
56 | $timers->{t1} = |
54 | urxvt::timer |
57 | urxvt::timer |