From 1380bad3d264dda7d06881d86f62025c0fecb3b2 Mon Sep 17 00:00:00 2001 From: Wojciech Siewierski Date: Fri, 13 Jan 2012 02:05:30 +0100 Subject: [PATCH 1/4] url-select: selected URLs are automatically copied When an URL is selected, it is copied to the clipboard using the selected tool. --- url-select | 13 +++++++++++++ 1 file changed, 13 insertions(+) mode change 100644 => 100755 url-select diff --git a/url-select b/url-select old mode 100644 new mode 100755 index 7b07b20..120d83d --- a/url-select +++ b/url-select @@ -24,6 +24,11 @@ # URxvt.urlLauncher: Browser/command to open selected URL with # URxvt.underlineURLs: If set to true, all URLs get underlined # URvxt.urlButton: Mouse button to click-open URLs (default: 2) +# URxvt.urlCopier: Command to copy the URL to the clipboard (optional) +# Recommended (and tested) - the following script: +# #!/bin/sh +# echo -n "$*" | xclip -in + use strict; @@ -37,6 +42,12 @@ sub on_start { my ($self) = @_; # read resource settings + if ($self->x_resource('urlCopier')) { + @{$self->{copier}} = split /\s+/, $self->x_resource('urlCopier'); + } else { + @{$self->{copier}} = (); + } + if ($self->x_resource('urlLauncher')) { @{$self->{browser}} = split /\s+/, $self->x_resource('urlLauncher'); } else { @@ -176,6 +187,7 @@ sub select_next { # another url on current line $self->{n} += $dir; hilight($self); + $self->exec_async(@{$self->{copier}}, $self->{found}->[$self->{n}]->[4]) if $self->{copier}; return; } @@ -199,6 +211,7 @@ sub select_next { $self->{row} = $row; $self->{n} = $dir < 0 ? $#{$self->{found}} : 0; hilight($self); + $self->exec_async(@{$self->{copier}}, $self->{found}->[$self->{n}]->[4]) if $self->{copier}; return; } } From 48762bc273648ad9fb94c887bb50aa3febee0f94 Mon Sep 17 00:00:00 2001 From: Wojciech Siewierski Date: Fri, 13 Jan 2012 11:29:22 +0100 Subject: [PATCH 2/4] url-select: much cleaner URL autocopy --- url-select | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/url-select b/url-select index 120d83d..f692a0f 100755 --- a/url-select +++ b/url-select @@ -24,11 +24,7 @@ # URxvt.urlLauncher: Browser/command to open selected URL with # URxvt.underlineURLs: If set to true, all URLs get underlined # URvxt.urlButton: Mouse button to click-open URLs (default: 2) -# URxvt.urlCopier: Command to copy the URL to the clipboard (optional) -# Recommended (and tested) - the following script: -# #!/bin/sh -# echo -n "$*" | xclip -in - +# URxvt.autoCopyURLs: If set to true, selected URLs are copied use strict; @@ -42,12 +38,6 @@ sub on_start { my ($self) = @_; # read resource settings - if ($self->x_resource('urlCopier')) { - @{$self->{copier}} = split /\s+/, $self->x_resource('urlCopier'); - } else { - @{$self->{copier}} = (); - } - if ($self->x_resource('urlLauncher')) { @{$self->{browser}} = split /\s+/, $self->x_resource('urlLauncher'); } else { @@ -56,6 +46,9 @@ sub on_start { if ($self->x_resource('underlineURLs') eq 'true') { $self->enable(line_update => \&line_update); } + if ($self->x_resource('autoCopyURLs') eq 'true') { + $self->{copy} = 1; + } if($self->x_resource('urlButton') =~ /^\d+$/) { $self->{button} = $self->x_resource('urlButton'); } else { @@ -116,17 +109,17 @@ sub key_press { $self->selection_grab($event->{time}); deactivate($self); } 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) { - select_next($self, 1); + select_next($self, 1, $event); } elsif ($char eq 'g' || $keysym == 0xff50) { $self->{row} = $self->top_row - 1; delete $self->{found}; - select_next($self, 1); + select_next($self, 1, $event); } elsif ($char eq 'G' || $keysym == 0xff57) { $self->{row} = $self->nrow; delete $self->{found}; - select_next($self, -1); + select_next($self, -1, $event); } return 1; @@ -179,7 +172,7 @@ sub on_button_release { sub select_next { # $dir < 0: up, > 0: down - my ($self, $dir) = @_; + my ($self, $dir, $event) = @_; my $row = $self->{row}; if (($dir < 0 && $self->{n} > 0) || @@ -187,12 +180,15 @@ sub select_next { # another url on current line $self->{n} += $dir; 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; } while (($dir < 0 && $row > $self->top_row) || - ($dir > 0 && $row < $self->nrow - 1)) { + ($dir > 0 && $row < $self->nrow - 1)) { my $line = $self->line($row); $row = ($dir < 0 ? $line->beg : $line->end) + $dir; $line = $self->line($row); @@ -211,7 +207,10 @@ sub select_next { $self->{row} = $row; $self->{n} = $dir < 0 ? $#{$self->{found}} : 0; 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; } } From c3977f556555b1f3f6af70cce23f3a2ef9c30c5c Mon Sep 17 00:00:00 2001 From: Wojciech Siewierski Date: Sun, 1 Apr 2012 00:14:06 +0200 Subject: [PATCH 3/4] updated README.md --- README.md | 2 ++ url-select | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 00736f2..07f0f8f 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,8 @@ Options: URxvt.urlLauncher: browser/command to open selected URL with URxvt.underlineURLs: if set to true, all URLs get underlined URvxt.urlButton: mouse button to click-open URLs (default: 2) + URxvt.autoCopyURLs: If set to true, selected URLs are automaticaly copied + to the PRIMARY clipboard clipboard diff --git a/url-select b/url-select index 6c844c7..fe3aa1a 100755 --- a/url-select +++ b/url-select @@ -25,7 +25,7 @@ # URxvt.underlineURLs: If set to true, all URLs get underlined # URvxt.urlButton: Mouse button to click-open URLs (default: 2) # URxvt.autoCopyURLs: If set to true, selected URLs are copied - +# to the PRIMARY clipboard use strict; From 21ed78a65033bd2853f98e4a3af456461bfb01ec Mon Sep 17 00:00:00 2001 From: Wojciech Siewierski Date: Mon, 2 Apr 2012 11:20:44 +0200 Subject: [PATCH 4/4] url-select: new selection method see: https://github.com/muennich/urxvt-perls/issues/18 --- url-select | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/url-select b/url-select index fe3aa1a..38d7b67 100755 --- a/url-select +++ b/url-select @@ -185,8 +185,12 @@ sub select_next { $self->{n} += $dir; hilight($self); if ($self->{copy}) { - $self->selection($self->{found}->[$self->{n}]->[4]); - $self->selection_grab($event->{time}); + my $found = $self->{found}[$self->{n}]; + $self->selection_beg(${$found}[0], ${$found}[1]); + $self->selection_end(${$found}[2], ${$found}[3]); + $self->selection_make($event->{time}); + $self->selection_beg(1, 0); + $self->selection_end(1, 0); } return; } @@ -212,13 +216,17 @@ sub select_next { $self->{n} = $dir < 0 ? $#{$self->{found}} : 0; hilight($self); if ($self->{copy}) { - $self->selection($self->{found}->[$self->{n}]->[4]); - $self->selection_grab($event->{time}); + my $found = $self->{found}[$self->{n}]; + $self->selection_beg(${$found}[0], ${$found}[1]); + $self->selection_end(${$found}[2], ${$found}[3]); + $self->selection_make($event->{time}); + $self->selection_beg(1, 0); + $self->selection_end(1, 0); } return; } } - + deactivate($self) unless $self->{found}; () @@ -334,4 +342,3 @@ sub deactivate { () } -