--- rxvt-unicode/src/perl/selection-pastebin 2006/03/10 21:36:16 1.16 +++ rxvt-unicode/src/perl/selection-pastebin 2014/05/31 08:33:47 1.25 @@ -1,5 +1,48 @@ #! perl +#:META:RESOURCE:%.cmd:string:the command to run create a new pastebin +#:META:RESOURCE:%.url:string:the url template for new pastebins + +=head1 NAME + +selection-pastebin - automatic pastebin upload + +=head1 EXAMPLES + + URxvt.keysym.C-M-e: selection-pastebin:remote-pastebin + +=head1 DESCRIPTION + +This is a little rarely useful extension that uploads the selection as +textfile to a remote site (or does other things). (The implementation is +not currently secure for use in a multiuser environment as it writes to +F directly.). + +It listens to the C action, which, +when activated, runs a command with C<%> replaced by the name of the +textfile. This command can be set via a resource: + + URxvt.selection-pastebin.cmd: rsync -apP % ruth:/var/www/www.ta-sa.org/files/txt/. + +And the default is likely not useful to anybody but the few people around +here :) + +The name of the textfile is the hex encoded md5 sum of the selection, so +the same content should lead to the same filename. + +After a successful upload the selection will be replaced by the text given +in the C resource (again, the % is the placeholder +for the filename): + + URxvt.selection-pastebin.url: http://www.ta-sa.org/files/txt/% + +I xrdb uses the C preprocessor, which might interpret +the double C characters as comment start. Use C<\057\057> instead, +which works regardless of whether xrdb is used to parse the resource file +or not. + +=cut + sub upload_paste { my ($self) = @_; @@ -26,7 +69,7 @@ my $cmd = $self->{pastebin_cmd}; $cmd =~ s/%/$tmpfile/; - my $pid = $self->exec_async ("/bin/sh", "-c", $cmd); + my $pid = $self->exec_async ($cmd); $self->{pw} = urxvt::pw->new->start ($pid)->cb (sub { my (undef, $status) = @_; @@ -59,10 +102,10 @@ sub on_start { my ($self) = @_; - $self->{pastebin_cmd} = $self->x_resource ("selection-pastebin.cmd") + $self->{pastebin_cmd} = $self->x_resource ("%.cmd") || "rcp -p % ruth:/var/www/www.ta-sa.org/files/txt/"; - $self->{pastebin_url} = $self->x_resource ("selection-pastebin.url") + $self->{pastebin_url} = $self->x_resource ("%.url") || "http://www.ta-sa.org/files/txt/%"; push @{ $self->{term}{selection_popup_hook} }, sub { @@ -72,12 +115,11 @@ () } -sub on_user_command { - my ($self, $cmd) = @_; +sub on_action { + my ($self, $action) = @_; - if ($cmd eq "selection-pastebin:remote-pastebin") { - $self->upload_paste; - } + $action eq "remote-pastebin" + and $self->upload_paste; () }