url-select: much cleaner URL autocopy

This commit is contained in:
Wojciech Siewierski 2012-01-13 11:29:22 +01:00
parent 1380bad3d2
commit 48762bc273

View File

@ -24,11 +24,7 @@
# URxvt.urlLauncher: Browser/command to open selected URL with # URxvt.urlLauncher: Browser/command to open selected URL with
# URxvt.underlineURLs: If set to true, all URLs get underlined # URxvt.underlineURLs: If set to true, all URLs get underlined
# URvxt.urlButton: Mouse button to click-open URLs (default: 2) # URvxt.urlButton: Mouse button to click-open URLs (default: 2)
# URxvt.urlCopier: Command to copy the URL to the clipboard (optional) # URxvt.autoCopyURLs: If set to true, selected URLs are copied
# Recommended (and tested) - the following script:
# #!/bin/sh
# echo -n "$*" | xclip -in
use strict; use strict;
@ -42,12 +38,6 @@ sub on_start {
my ($self) = @_; my ($self) = @_;
# read resource settings # read resource settings
if ($self->x_resource('urlCopier')) {
@{$self->{copier}} = split /\s+/, $self->x_resource('urlCopier');
} else {
@{$self->{copier}} = ();
}
if ($self->x_resource('urlLauncher')) { if ($self->x_resource('urlLauncher')) {
@{$self->{browser}} = split /\s+/, $self->x_resource('urlLauncher'); @{$self->{browser}} = split /\s+/, $self->x_resource('urlLauncher');
} else { } else {
@ -56,6 +46,9 @@ sub on_start {
if ($self->x_resource('underlineURLs') eq 'true') { if ($self->x_resource('underlineURLs') eq 'true') {
$self->enable(line_update => \&line_update); $self->enable(line_update => \&line_update);
} }
if ($self->x_resource('autoCopyURLs') eq 'true') {
$self->{copy} = 1;
}
if($self->x_resource('urlButton') =~ /^\d+$/) { if($self->x_resource('urlButton') =~ /^\d+$/) {
$self->{button} = $self->x_resource('urlButton'); $self->{button} = $self->x_resource('urlButton');
} else { } else {
@ -116,17 +109,17 @@ sub key_press {
$self->selection_grab($event->{time}); $self->selection_grab($event->{time});
deactivate($self); deactivate($self);
} elsif ($char eq 'k' || $keysym == 0xff52 || $keysym == 0xff51) { } elsif ($char eq 'k' || $keysym == 0xff52 || $keysym == 0xff51) {
select_next($self, -1); select_next($self, -1, $event);
} elsif ($char eq 'j' || $keysym == 0xff54 || $keysym == 0xff53) { } elsif ($char eq 'j' || $keysym == 0xff54 || $keysym == 0xff53) {
select_next($self, 1); select_next($self, 1, $event);
} elsif ($char eq 'g' || $keysym == 0xff50) { } elsif ($char eq 'g' || $keysym == 0xff50) {
$self->{row} = $self->top_row - 1; $self->{row} = $self->top_row - 1;
delete $self->{found}; delete $self->{found};
select_next($self, 1); select_next($self, 1, $event);
} elsif ($char eq 'G' || $keysym == 0xff57) { } elsif ($char eq 'G' || $keysym == 0xff57) {
$self->{row} = $self->nrow; $self->{row} = $self->nrow;
delete $self->{found}; delete $self->{found};
select_next($self, -1); select_next($self, -1, $event);
} }
return 1; return 1;
@ -179,7 +172,7 @@ sub on_button_release {
sub select_next { sub select_next {
# $dir < 0: up, > 0: down # $dir < 0: up, > 0: down
my ($self, $dir) = @_; my ($self, $dir, $event) = @_;
my $row = $self->{row}; my $row = $self->{row};
if (($dir < 0 && $self->{n} > 0) || if (($dir < 0 && $self->{n} > 0) ||
@ -187,7 +180,10 @@ sub select_next {
# another url on current line # another url on current line
$self->{n} += $dir; $self->{n} += $dir;
hilight($self); hilight($self);
$self->exec_async(@{$self->{copier}}, $self->{found}->[$self->{n}]->[4]) if $self->{copier}; if ($self->{copy}) {
$self->selection($self->{found}->[$self->{n}]->[4]);
$self->selection_grab($event->{time});
}
return; return;
} }
@ -211,7 +207,10 @@ sub select_next {
$self->{row} = $row; $self->{row} = $row;
$self->{n} = $dir < 0 ? $#{$self->{found}} : 0; $self->{n} = $dir < 0 ? $#{$self->{found}} : 0;
hilight($self); hilight($self);
$self->exec_async(@{$self->{copier}}, $self->{found}->[$self->{n}]->[4]) if $self->{copier}; if ($self->{copy}) {
$self->selection($self->{found}->[$self->{n}]->[4]);
$self->selection_grab($event->{time});
}
return; return;
} }
} }