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

# 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 root 1.10
53 root 1.5 $pastebin_cmd = $self->x_resource ("selection-pastebin.cmd")
54 root 1.7 || "rcp -p % ruth:/var/www/www.ta-sa.org/files/txt/";
55 root 1.5
56     $pastebin_url = $self->x_resource ("selection-pastebin.url")
57     || "http://www.ta-sa.org/files/txt/%";
58    
59 root 1.10 push @{ $self->{term}{selection_popup_hook} }, sub {
60     ("pastebin upload" => sub { $self->upload_paste })
61     };
62    
63 root 1.5 ()
64     }
65    
66 elmex 1.1 sub on_keyboard_command {
67     my ($self, $cmd) = @_;
68    
69 root 1.5 if ($cmd eq "selection-pastebin:remote-pastebin") {
70     $self->upload_paste;
71     }
72 elmex 1.1
73     ()
74     }
75