| Revision: | 1.16 |
| Committed: | Fri Mar 10 21:36:16 2006 UTC (20 years, 7 months ago) by root |
| Branch: | MAIN |
| CVS Tags: | before_dynamic_fontidx, rel-7_8, rel-7_9, rel-9_11, rel-9_10, rel-8_1, rel-9_12, rel-8_5a, rel-8_2, rel-8_9, rel-8_8, dynamic_fontidx, rel-8_0, rel-8_4, rel-9_0, rel-8_3, rel-8_6, rel-8_7, rel-9_09, rel-9_02, rel-9_01, rel-9_06, rel-9_07, rel-9_05 |
| Changes since 1.15: | +4 -1 lines |
| Log Message: | *** empty log message *** |
| # | User | Rev | Content |
|---|---|---|---|
| 1 | elmex | 1.1 | #! perl |
| 2 | |||
| 3 | sub upload_paste { | ||
| 4 | my ($self) = @_; | ||
| 5 | |||
| 6 | root | 1.2 | require Digest::MD5; |
| 7 | elmex | 1.1 | |
| 8 | my $txt = $self->selection; | ||
| 9 | root | 1.16 | |
| 10 | my $filename = $txt; | ||
| 11 | utf8::encode $filename; | ||
| 12 | $filename = Digest::MD5::md5_hex ($filename) . ".txt"; | ||
| 13 | elmex | 1.1 | |
| 14 | my $tmpfile = "/tmp/$filename"; | ||
| 15 | |||
| 16 | root | 1.12 | my $msg = "uploaded as $filename"; |
| 17 | elmex | 1.1 | |
| 18 | root | 1.14 | if (open my $o, ">:utf8", $tmpfile) { |
| 19 | root | 1.6 | chmod 0644, $tmpfile; |
| 20 | elmex | 1.1 | print $o $txt; |
| 21 | close $o; | ||
| 22 | } else { | ||
| 23 | $msg = "couldn't write $tmpfile: $!"; | ||
| 24 | } | ||
| 25 | |||
| 26 | root | 1.14 | my $cmd = $self->{pastebin_cmd}; |
| 27 | elmex | 1.1 | $cmd =~ s/%/$tmpfile/; |
| 28 | |||
| 29 | root | 1.14 | my $pid = $self->exec_async ("/bin/sh", "-c", $cmd); |
| 30 | elmex | 1.1 | |
| 31 | root | 1.14 | $self->{pw} = urxvt::pw->new->start ($pid)->cb (sub { |
| 32 | my (undef, $status) = @_; | ||
| 33 | elmex | 1.4 | |
| 34 | root | 1.14 | delete $self->{pw}; |
| 35 | elmex | 1.1 | |
| 36 | root | 1.14 | if ($status) { |
| 37 | $status >>= 8; | ||
| 38 | $msg = "ERROR: command returned status $status"; | ||
| 39 | } else { | ||
| 40 | my $url = $self->{pastebin_url}; | ||
| 41 | $url =~ s/%/$filename/; | ||
| 42 | |||
| 43 | $self->selection ($url); | ||
| 44 | } | ||
| 45 | |||
| 46 | unlink $tmpfile; | ||
| 47 | |||
| 48 | my $ov = $self->overlay (-1, 0, $self->strwidth ($msg), 1, urxvt::OVERLAY_RSTYLE, 0); | ||
| 49 | $ov->set (0, 0, $msg); | ||
| 50 | |||
| 51 | $self->{timer} = | ||
| 52 | urxvt::timer | ||
| 53 | ->new | ||
| 54 | ->after (5) | ||
| 55 | ->cb (sub { delete $self->{timer}; undef $ov; }); | ||
| 56 | }); | ||
| 57 | elmex | 1.1 | } |
| 58 | |||
| 59 | root | 1.5 | sub on_start { |
| 60 | my ($self) = @_; | ||
| 61 | root | 1.10 | |
| 62 | root | 1.14 | $self->{pastebin_cmd} = $self->x_resource ("selection-pastebin.cmd") |
| 63 | || "rcp -p % ruth:/var/www/www.ta-sa.org/files/txt/"; | ||
| 64 | root | 1.5 | |
| 65 | root | 1.14 | $self->{pastebin_url} = $self->x_resource ("selection-pastebin.url") |
| 66 | || "http://www.ta-sa.org/files/txt/%"; | ||
| 67 | root | 1.5 | |
| 68 | root | 1.10 | push @{ $self->{term}{selection_popup_hook} }, sub { |
| 69 | ("pastebin upload" => sub { $self->upload_paste }) | ||
| 70 | }; | ||
| 71 | |||
| 72 | root | 1.5 | () |
| 73 | } | ||
| 74 | |||
| 75 | root | 1.15 | sub on_user_command { |
| 76 | elmex | 1.1 | my ($self, $cmd) = @_; |
| 77 | |||
| 78 | root | 1.5 | if ($cmd eq "selection-pastebin:remote-pastebin") { |
| 79 | $self->upload_paste; | ||
| 80 | } | ||
| 81 | elmex | 1.1 | |
| 82 | () | ||
| 83 | } | ||
| 84 |