ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/perl/selection-pastebin
Revision: 1.2
Committed: Tue Jan 17 16:57:07 2006 UTC (18 years, 4 months ago) by root
Branch: MAIN
Changes since 1.1: +4 -3 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 #! perl
2
3 my $timers = {};
4 my $pastebin_cmd;
5 my $pastebin_url;
6
7 sub on_start {
8 my ($self) = @_;
9 $pastebin_cmd =
10 $self->x_resource ("selection-pastebin-cmd")
11 or "scp -p % ruth:/var/www/www.ta-sa.org/files/txt/";
12
13 $pastebin_url =
14 $self->x_resource ("selection-pastebin-url")
15 or "http://www.ta-sa.org/files/txt/";
16
17 ()
18 }
19
20 sub upload_paste {
21 my ($self) = @_;
22
23 require Digest::MD5;
24
25 my $txt = $self->selection;
26 my $filename = Digest::MD5::md5_hex ($txt) . ".txt";
27
28 my $tmpfile = "/tmp/$filename";
29
30 my $msg = "uploaded $filename";
31
32 if (open my $o, ">" . $tmpfile) {
33 print $o $txt;
34 close $o;
35 } else {
36 $msg = "couldn't write $tmpfile: $!";
37 }
38
39 my $cmd = $pastebin_cmd;
40 $cmd =~ s/%/$tmpfile/;
41
42 if (system ($cmd) == 0) {
43 my $url = $pastebin_url;
44 $url =~ s/%/$filename/;
45
46 $self->selection ($url);
47 } else {
48 $msg = "couldn't upload, '$cmd' failed";
49 }
50
51 my $ov = $timers->{ov} = $self->overlay (-1, 0, length ($msg), 1, urxvt::OVERLAY_RSTYLE, 0);
52 $ov->set (0, 0, $msg);
53
54 $timers->{t1} =
55 urxvt::timer
56 ->new
57 ->start ((int urxvt::NOW) + 5) # make sure we update "on" the second
58 ->interval (1)
59 ->cb (sub { delete $timers->{ov}; delete $timers->{t1}; });
60 }
61
62 sub on_keyboard_command {
63 my ($self, $cmd) = @_;
64
65 $cmd eq "selection-pastebin:remote-pastebin"
66 and upload_paste ($self);
67
68 ()
69 }
70