ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/perl/selection-pastebin
Revision: 1.10
Committed: Thu Jan 19 16:22:13 2006 UTC (18 years, 4 months ago) by root
Branch: MAIN
Changes since 1.9: +5 -4 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 #! perl
2
3 my $pastebin_cmd;
4 my $pastebin_url;
5
6 sub upload_paste {
7 my ($self) = @_;
8
9 require Digest::MD5;
10
11 my $txt = $self->selection;
12 my $filename = Digest::MD5::md5_hex ($txt) . ".txt";
13
14 my $tmpfile = "/tmp/$filename";
15
16 my $msg = "uploaded $filename";
17
18 if (open my $o, ">", $tmpfile) {
19 chmod 0644, $tmpfile;
20 print $o $txt;
21 close $o;
22 } else {
23 $msg = "couldn't write $tmpfile: $!";
24 }
25
26 my $cmd = $pastebin_cmd;
27 $cmd =~ s/%/$tmpfile/;
28
29 if (system ($cmd) == 0) {
30 my $url = $pastebin_url;
31 $url =~ s/%/$filename/;
32
33 $self->selection ($url);
34 } else {
35 $msg = "couldn't upload, '$cmd' failed";
36 }
37
38 unlink $tmpfile;
39
40 my $ov = $self->overlay (-1, 0, length $msg, 1, urxvt::OVERLAY_RSTYLE, 0);
41 $ov->set (0, 0, $msg);
42
43 my $timer; $timer =
44 urxvt::timer
45 ->new
46 ->after (5)
47 ->cb (sub {undef $timer; undef $ov; });
48 }
49
50 sub on_start {
51 my ($self) = @_;
52
53 $pastebin_cmd = $self->x_resource ("selection-pastebin.cmd")
54 || "rcp -p % ruth:/var/www/www.ta-sa.org/files/txt/";
55
56 $pastebin_url = $self->x_resource ("selection-pastebin.url")
57 || "http://www.ta-sa.org/files/txt/%";
58
59 push @{ $self->{term}{selection_popup_hook} }, sub {
60 ("pastebin upload" => sub { $self->upload_paste })
61 };
62
63 ()
64 }
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