Permalink
Browse files

isgd.pl: Shorten up to n last found URLs

  • Loading branch information...
1 parent f2733ee commit 392e9a9ecce2fe21f4212c7fd04d36230104d452 @stfnm committed Jul 18, 2012
Showing with 6 additions and 3 deletions.
  1. +6 −3 perl/isgd.pl
View
@@ -41,9 +41,10 @@
weechat::register($SCRIPT{"name"}, $SCRIPT{"author"}, $SCRIPT{"version"}, $SCRIPT{"license"}, $SCRIPT{"desc"}, "", "");
weechat::hook_command($SCRIPT{"name"}, $SCRIPT{"desc"},
- "[<URL> ...]\n",
+ "[<URL> ...] | [<number>]\n",
"Without any URL arguments, the last found URL in the current buffer will be shortened.\n\n" .
- "URL: URL to shorten. More than one URL may be given.",
+ "URL: URL to shorten. More than one URL may be given.\n" .
+ "number: shorten up to last found n URLs in current buffer.",
"", "command_cb", "");
init_config();
@@ -59,14 +60,16 @@ sub command_cb
}
# Otherwise search backwards in lines of current buffer
if (@URLs == 0) {
+ my $count = 1;
+ $count = $1 if ($args =~ /^(\d+)$/);
my $infolist = weechat::infolist_get("buffer_lines", $buffer, "");
while (weechat::infolist_prev($infolist) == 1) {
my $message = weechat::infolist_string($infolist, "message");
while ($message =~ m{(https?://\S+)}gi) {
my $url = $1;
push(@URLs, $url) unless ($url =~ m{^https?://is\.gd/}gi);
}
- last if (@URLs > 0);
+ last if (@URLs >= $count);
}
weechat::infolist_free($infolist);
}

0 comments on commit 392e9a9

Please sign in to comment.