ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/perl/selection
(Generate patch)

Comparing rxvt-unicode/src/perl/selection (file contents):
Revision 1.27 by elmex, Tue Jan 17 13:07:16 2006 UTC vs.
Revision 1.29 by root, Tue Jan 17 16:22:41 2006 UTC

5my $pastebin_cmd; 5my $pastebin_cmd;
6my $pastebin_url; 6my $pastebin_url;
7 7
8sub on_start { 8sub on_start {
9 my ($self) = @_; 9 my ($self) = @_;
10 $pastebin_cmd =
11 (urxvt::untaint $self->x_resource ("selection-pastebin-cmd")) 10 $pastebin_cmd = $self->x_resource ("selection-pastebin-cmd")
12 or "scp -p % ruth:/var/www/www.ta-sa.org/files/txt/"; 11 or "scp -p % ruth:/var/www/www.ta-sa.org/files/txt/";
13 12
14 $pastebin_url =
15 (urxvt::untaint $self->x_resource ("selection-pastebin-url")) 13 $pastebin_url = $self->x_resource ("selection-pastebin-url")
16 or "http://www.ta-sa.org/files/txt/"; 14 or "http://www.ta-sa.org/files/txt/";
17 (); 15 ();
18} 16}
19 17
20sub upload_paste { 18sub upload_paste {
21 my ($self) = @_; 19 my ($self) = @_;
22 20
23 my $txt = $self->selection; 21 my $txt = $self->selection;
24 my $h = md5_hex ($txt); 22 my $filename = md5_hex ($txt) . ".txt";
25 23
26 my $fn = "/tmp/$h.txt"; 24 my $tmpfile = "/tmp/$filename";
27 25
28 my $msg = "uploaded $h.txt"; 26 my $msg = "uploaded $filename";
29 27
30 if (open my $o, ">" . $fn) { 28 if (open my $o, ">" . $tmpfile) {
31 print $o $txt; 29 print $o $txt;
32 close $o; 30 close $o;
33 } else { 31 } else {
34 $msg = "couldn't write $fn: $!"; 32 $msg = "couldn't write $tmpfile: $!";
35 } 33 }
36 34
37 my $cmd = $pastebin_cmd; 35 my $cmd = $pastebin_cmd;
38 $cmd =~ s/%/$fn/; 36 $cmd =~ s/%/$tmpfile/;
37
39 unless (system ($cmd) == 0) { 38 if (system ($cmd) == 0) {
39
40 my $url = $pastebin_url;
41 $url =~ s/%/$filename/;
42
43 $self->selection ($url);
44 } else {
40 $msg = "couldn't upload, '$cmd' failed"; 45 $msg = "couldn't upload, '$cmd' failed";
41 } 46 }
42
43 $self->selection ($pastebin_url . "$h.txt");
44 47
45 my $ov = $timers->{ov} = $self->overlay (-1, 0, length ($msg), 1, urxvt::OVERLAY_RSTYLE, 0); 48 my $ov = $timers->{ov} = $self->overlay (-1, 0, length ($msg), 1, urxvt::OVERLAY_RSTYLE, 0);
46 $ov->set (0, 0, $msg); 49 $ov->set (0, 0, $msg);
47 50
48 $timers->{t1} = 51 $timers->{t1} =

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines