aboutsummaryrefslogtreecommitdiffstats
path: root/tinyurl-tabcomplete/complete-tiny-url.pl
diff options
context:
space:
mode:
authorTom Feist <shabble@cowu.be>2010-09-16 14:27:29 +0000
committerTom Feist <shabble@cowu.be>2010-09-16 14:27:29 +0000
commitd86eb93366df577f6a6bdaef0032ee9ee9cf10b4 (patch)
treea1431b6b6c0332d17cb81ee7fc9f78224825da98 /tinyurl-tabcomplete/complete-tiny-url.pl
parentadded a script to tab-complete URIs into their tinified equivalents (diff)
downloadirssi-scripts-d86eb93366df577f6a6bdaef0032ee9ee9cf10b4.tar.gz
irssi-scripts-d86eb93366df577f6a6bdaef0032ee9ee9cf10b4.zip
modified it to use DaringFireball liberal uri match rather than re::common to handle more cases
Diffstat (limited to 'tinyurl-tabcomplete/complete-tiny-url.pl')
-rw-r--r--tinyurl-tabcomplete/complete-tiny-url.pl45
1 files changed, 42 insertions, 3 deletions
diff --git a/tinyurl-tabcomplete/complete-tiny-url.pl b/tinyurl-tabcomplete/complete-tiny-url.pl
index def9440..e3100e4 100644
--- a/tinyurl-tabcomplete/complete-tiny-url.pl
+++ b/tinyurl-tabcomplete/complete-tiny-url.pl
@@ -2,7 +2,6 @@ use strict;
use vars qw($VERSION %IRSSI);
use Irssi;
-use Regexp::Common qw/URI/;
use WWW::Shorten::TinyURL;
$VERSION = '2.1';
@@ -17,13 +16,53 @@ $VERSION = '2.1';
sub do_complete {
my ($strings, $window, $word, $linestart, $want_space) = @_;
return if $word eq '';
- if ($word =~ m/$RE{URI}{HTTP}{-keep}/) {
- my $uri = makeashorterlink($1);
+ if (defined (my $found_uri = match_uri($word))) {
+ my $uri = makeashorterlink($found_uri);
push @$strings, $uri if $uri;
$$want_space = 1;
Irssi::signal_stop();
}
}
+sub match_uri {
+ my $text = shift;
+
+ my $regex = qr((?xi)
+\b
+( # Capture 1: entire matched URL
+ (?:
+ [a-z][\w-]+: # URL protocol and colon
+ (?:
+ /{1,3} # 1-3 slashes
+ | # or
+ [a-z0-9%] # Single letter or digit or '%'
+ # (Trying not to match e.g. "URI::Escape")
+ )
+ | # or
+ www\d{0,3}[.] # "www.", "www1.", "www2." … "www999."
+ | # or
+ [a-z0-9.\-]+[.][a-z]{2,4}/ # looks like domain name followed by a slash
+ )
+ (?: # One or more:
+ [^\s()<>]+ # Run of non-space, non-()<>
+ | # or
+ \(([^\s()<>]+|(\([^\s()<>]+\)))*\) # balanced parens, up to 2 levels
+ )+
+ (?: # End with:
+ \(([^\s()<>]+|(\([^\s()<>]+\)))*\) # balanced parens, up to 2 levels
+ | # or
+ [^\s`!()\[\]{};:'".,<>?«»“”‘’] # not a space or one of these punct chars
+ )
+));
+
+ if ($text =~ $regex) {
+ my $uri = $1;
+ $uri = 'http://' . $uri if $uri !~ m(http://);
+ return $uri;
+ } else {
+ return '';
+ }
+}
+
Irssi::signal_add_first( 'complete word', \&do_complete);