From b8ab87803b61f8d0aad12c9387a0bbefca1ea198 Mon Sep 17 00:00:00 2001 From: elmex Date: Tue, 17 Jan 2006 16:53:47 +0000 Subject: [PATCH] moved pastebin code from selection to src/perl/selection-pastebin and corrected documentation --- Changes | 2 +- src/perl/selection | 59 ------------------------------- src/perl/selection-pastebin | 69 +++++++++++++++++++++++++++++++++++++ src/urxvt.pm | 34 +++++++++--------- 4 files changed, 87 insertions(+), 77 deletions(-) create mode 100644 src/perl/selection-pastebin diff --git a/Changes b/Changes index f81ecba6..277129f3 100644 --- a/Changes +++ b/Changes @@ -13,13 +13,13 @@ WISH: just for fun, do shade and tint with XRender. WISH: support tex fonts 9.0 + - new script: perl/selection-pastebin - improved security of setuid/setgid operation, which is now encouraged, by moving privileged operations into a separate process and permanently dropping privileges within the terminal. This makes it possible to remove security checks from the perl code and gives a much safer feeling when urxvt needs to run with special privileges. - - implemented perl:selection:remote-pastebin command in perl/selection - use the scrollback buffer even when the scroll region doesn't span the whole screen, as long as it starts at row 0. - swap the environment in some more cases. This hopefully fixes diff --git a/src/perl/selection b/src/perl/selection index 26f5277c..ca71f9c3 100644 --- a/src/perl/selection +++ b/src/perl/selection @@ -1,60 +1,4 @@ #! perl -use Digest::MD5 qw/md5_hex/; - -my $timers = {}; -my $pastebin_cmd; -my $pastebin_url; - -sub on_start { - my ($self) = @_; - $pastebin_cmd = $self->x_resource ("selection-pastebin-cmd") - or "scp -p % ruth:/var/www/www.ta-sa.org/files/txt/"; - - $pastebin_url = $self->x_resource ("selection-pastebin-url") - or "http://www.ta-sa.org/files/txt/"; - (); -} - -sub upload_paste { - my ($self) = @_; - - my $txt = $self->selection; - my $filename = md5_hex ($txt) . ".txt"; - - my $tmpfile = "/tmp/$filename"; - - my $msg = "uploaded $filename"; - - if (open my $o, ">" . $tmpfile) { - print $o $txt; - close $o; - } else { - $msg = "couldn't write $tmpfile: $!"; - } - - my $cmd = $pastebin_cmd; - $cmd =~ s/%/$tmpfile/; - - if (system ($cmd) == 0) { - - my $url = $pastebin_url; - $url =~ s/%/$filename/; - - $self->selection ($url); - } else { - $msg = "couldn't upload, '$cmd' failed"; - } - - my $ov = $timers->{ov} = $self->overlay (-1, 0, length ($msg), 1, urxvt::OVERLAY_RSTYLE, 0); - $ov->set (0, 0, $msg); - - $timers->{t1} = - urxvt::timer - ->new - ->start ((int urxvt::NOW) + 5) # make sure we update "on" the second - ->interval (1) - ->cb (sub { delete $timers->{ov}; delete $timers->{t1}; }); -} sub on_keyboard_command { my ($self, $cmd) = @_; @@ -62,9 +6,6 @@ sub on_keyboard_command { $cmd eq "selection:rot13" and $self->selection (map { y/A-Za-z/N-ZA-Mn-za-m/; $_ } $self->selection); - $cmd eq "selection:remote-pastebin" - and upload_paste ($self); - () } diff --git a/src/perl/selection-pastebin b/src/perl/selection-pastebin new file mode 100644 index 00000000..aea02588 --- /dev/null +++ b/src/perl/selection-pastebin @@ -0,0 +1,69 @@ +#! perl +use Digest::MD5 qw/md5_hex/; + +my $timers = {}; +my $pastebin_cmd; +my $pastebin_url; + +sub on_start { + my ($self) = @_; + $pastebin_cmd = + $self->x_resource ("selection-pastebin-cmd") + or "scp -p % ruth:/var/www/www.ta-sa.org/files/txt/"; + + $pastebin_url = + $self->x_resource ("selection-pastebin-url") + or "http://www.ta-sa.org/files/txt/"; + (); +} + +sub upload_paste { + my ($self) = @_; + + + my $txt = $self->selection; + my $filename = md5_hex ($txt) . ".txt"; + + my $tmpfile = "/tmp/$filename"; + + my $msg = "uploaded $filename"; + + if (open my $o, ">" . $tmpfile) { + print $o $txt; + close $o; + } else { + $msg = "couldn't write $tmpfile: $!"; + } + + my $cmd = $pastebin_cmd; + $cmd =~ s/%/$tmpfile/; + + if (system ($cmd) == 0) { + my $url = $pastebin_url; + $url =~ s/%/$filename/; + + $self->selection ($url); + } else { + $msg = "couldn't upload, '$cmd' failed"; + } + + my $ov = $timers->{ov} = $self->overlay (-1, 0, length ($msg), 1, urxvt::OVERLAY_RSTYLE, 0); + $ov->set (0, 0, $msg); + + $timers->{t1} = + urxvt::timer + ->new + ->start ((int urxvt::NOW) + 5) # make sure we update "on" the second + ->interval (1) + ->cb (sub { delete $timers->{ov}; delete $timers->{t1}; }); +} + +sub on_keyboard_command { + my ($self, $cmd) = @_; + + $cmd eq "selection-pastebin:remote-pastebin" + and upload_paste ($self); + + () +} + diff --git a/src/urxvt.pm b/src/urxvt.pm index f2cadb82..b565adf7 100644 --- a/src/urxvt.pm +++ b/src/urxvt.pm @@ -78,23 +78,6 @@ Rot-13 the selection when activated. Used via keyboard trigger: URxvt.keysym.C-M-r: perl:selection:rot13 -=item remote-pastebin - -Upload the selection as textfile to a remote site. - - URxvt.keysym.C-M-e: perl:selection:remote-pastebin - -To set the command to upload the file set this resource: - - URxvt.selection-pastebin-cmd: rsync -apP % ruth:/var/www/www.ta-sa.org/files/txt/. - -The % is the placeholder for the textfile. The name of the textfile is the hex encoded -md5 sum of the selection. -After an successful upload the selection will be replaced by the following url -(the % is the placeholder for the filename): - - URxvt.selection-pastebin-url: http://www.ta-sa.org/files/txt/% - =back =item option-popup (enabled by default) @@ -181,6 +164,23 @@ Displays a very simple digital clock in the upper right corner of the window. Illustrates overwriting the refresh callbacks to create your own overlays or changes. +=item selection-pastebin + +Uploads the selection as textfile to a remote site. + + URxvt.keysym.C-M-e: perl:selection-pastebin:remote-pastebin + +To set the command to upload the file set this resource: + + URxvt.selection-pastebin-cmd: rsync -apP % ruth:/var/www/www.ta-sa.org/files/txt/. + +The % is the placeholder for the textfile. The name of the textfile is the hex encoded +md5 sum of the selection. +After an successful upload the selection will be replaced by the following url +(the % is the placeholder for the filename): + + URxvt.selection-pastebin-url: http://www.ta-sa.org/files/txt/% + =back =head1 API DOCUMENTATION -- 2.34.1