… | |
… | |
19 | |
19 | |
20 | sub upload_paste { |
20 | sub upload_paste { |
21 | my ($self) = @_; |
21 | my ($self) = @_; |
22 | |
22 | |
23 | my $txt = $self->selection; |
23 | my $txt = $self->selection; |
24 | my $h = md5_hex ($txt); |
24 | my $filename = md5_hex ($txt) . ".txt"; |
25 | |
25 | |
26 | my $fn = "/tmp/$h.txt"; |
26 | my $tmpfile = "/tmp/$filename"; |
27 | |
27 | |
28 | my $msg = "uploaded $h.txt"; |
28 | my $msg = "uploaded $filename"; |
29 | |
29 | |
30 | if (open my $o, ">" . $fn) { |
30 | if (open my $o, ">" . $tmpfile) { |
31 | print $o $txt; |
31 | print $o $txt; |
32 | close $o; |
32 | close $o; |
33 | } else { |
33 | } else { |
34 | $msg = "couldn't write $fn: $!"; |
34 | $msg = "couldn't write $tmpfile: $!"; |
35 | } |
35 | } |
36 | |
36 | |
37 | my $cmd = $pastebin_cmd; |
37 | my $cmd = $pastebin_cmd; |
38 | $cmd =~ s/%/$fn/; |
38 | $cmd =~ s/%/$tmpfile/; |
|
|
39 | |
39 | unless (system ($cmd) == 0) { |
40 | if (system ($cmd) == 0) { |
|
|
41 | |
|
|
42 | my $url = $pastebin_url; |
|
|
43 | $url =~ s/%/$filename/; |
|
|
44 | |
|
|
45 | $self->selection ($url); |
|
|
46 | } else { |
40 | $msg = "couldn't upload, '$cmd' failed"; |
47 | $msg = "couldn't upload, '$cmd' failed"; |
41 | } |
48 | } |
42 | |
|
|
43 | $self->selection ($pastebin_url . "$h.txt"); |
|
|
44 | |
49 | |
45 | my $ov = $timers->{ov} = $self->overlay (-1, 0, length ($msg), 1, urxvt::OVERLAY_RSTYLE, 0); |
50 | my $ov = $timers->{ov} = $self->overlay (-1, 0, length ($msg), 1, urxvt::OVERLAY_RSTYLE, 0); |
46 | $ov->set (0, 0, $msg); |
51 | $ov->set (0, 0, $msg); |
47 | |
52 | |
48 | $timers->{t1} = |
53 | $timers->{t1} = |