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

File Contents

# User Rev Content
1 elmex 1.1 #! perl
2    
3     my $pastebin_cmd;
4     my $pastebin_url;
5    
6     sub upload_paste {
7     my ($self) = @_;
8    
9 root 1.2 require Digest::MD5;
10 elmex 1.1
11     my $txt = $self->selection;
12 root 1.2 my $filename = Digest::MD5::md5_hex ($txt) . ".txt";
13 elmex 1.1
14     my $tmpfile = "/tmp/$filename";
15    
16     my $msg = "uploaded $filename";
17    
18 root 1.7 if (open my $o, ">", $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     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 elmex 1.4 unlink $tmpfile;
39    
40 root 1.7 my $ov = $self->overlay (-1, 0, length $msg, 1, urxvt::OVERLAY_RSTYLE, 0);
41 elmex 1.1 $ov->set (0, 0, $msg);
42    
43 root 1.7 my $timer; $timer =
44 elmex 1.1 urxvt::timer
45     ->new
46 root 1.8 ->after (5)
47 root 1.7 ->cb (sub {undef $timer; undef $ov; });
48 elmex 1.1 }
49    
50 root 1.5 sub on_start {
51     my ($self) = @_;
52     $pastebin_cmd = $self->x_resource ("selection-pastebin.cmd")
53 root 1.7 || "rcp -p % ruth:/var/www/www.ta-sa.org/files/txt/";
54 root 1.5
55     $pastebin_url = $self->x_resource ("selection-pastebin.url")
56     || "http://www.ta-sa.org/files/txt/%";
57    
58     ()
59     }
60    
61 root 1.9 push @urxvt::ext::selection_popup::hook, sub {
62     ("pastebin upload" => sub { $self->upload_paste })
63     };
64    
65 elmex 1.1 sub on_keyboard_command {
66     my ($self, $cmd) = @_;
67    
68 root 1.5 if ($cmd eq "selection-pastebin:remote-pastebin") {
69     $self->upload_paste;
70     }
71 elmex 1.1
72     ()
73     }
74