--- /dev/null
+#! perl
+
+# same url as used in "selection"
+my $url =
+ qr{(
+ (?:https?|ftp|news|mailto|file)://[ab-zA-Z0-9\-\@;\/?:&=%\$_.+!*\x27(),]+
+ [^.] # do not include a trailing dot, its wrong too often
+ )}x;
+
+sub on_add_lines {
+ my ($term, $str) = @_;
+
+ while ($str =~ $url) {
+ # found a url, first output preceding text
+ $term->scr_add_lines (substr $str, 0, $-[1], "");
+ # then toggle underline
+ $term->rstyle ($term->rstyle ^ urxvt::RS_Uline);
+ # now output the url
+ $term->scr_add_lines (substr $str, 0, $+[1] - $-[1], "");
+ # toggle undelrine again
+ $term->rstyle ($term->rstyle ^ urxvt::RS_Uline);
+ }
+
+ # output trailing text
+ $term->scr_add_lines ($str);
+
+ 1
+}
+