play.pl: -find limit and detect empty files
This commit is contained in:
parent
2ae017aba6
commit
a7a0b72546
@ -5,7 +5,7 @@ no strict 'subs';
|
|||||||
|
|
||||||
my $SCRIPT_NAME = 'play';
|
my $SCRIPT_NAME = 'play';
|
||||||
my $SCRIPT_AUTHOR = 'The Krusty Krab <wowaname@volatile.ch>';
|
my $SCRIPT_AUTHOR = 'The Krusty Krab <wowaname@volatile.ch>';
|
||||||
my $SCRIPT_VERSION = '1.1';
|
my $SCRIPT_VERSION = '1.2';
|
||||||
my $SCRIPT_LICENCE = 'Public domain';
|
my $SCRIPT_LICENCE = 'Public domain';
|
||||||
my $SCRIPT_DESC = 'Play ASCII art';
|
my $SCRIPT_DESC = 'Play ASCII art';
|
||||||
our (%queue, %timer);
|
our (%queue, %timer);
|
||||||
@ -28,6 +28,8 @@ if (weechat::register($SCRIPT_NAME, $SCRIPT_AUTHOR, $SCRIPT_VERSION,
|
|||||||
delay => ['Default delay between lines', 0],
|
delay => ['Default delay between lines', 0],
|
||||||
dir => ['Art directory',
|
dir => ['Art directory',
|
||||||
weechat::info_get('weechat_dir', '').'/ascii'],
|
weechat::info_get('weechat_dir', '').'/ascii'],
|
||||||
|
find_limit => ['Maximum number of results returned by -find. '.
|
||||||
|
'-1 = unlimited (may lock up WeeChat with many results!)', 32],
|
||||||
);
|
);
|
||||||
|
|
||||||
for my $option (keys %OPTIONS) {
|
for my $option (keys %OPTIONS) {
|
||||||
@ -99,11 +101,17 @@ sub cmd_play {
|
|||||||
: weechat::config_integer($prio_s)
|
: weechat::config_integer($prio_s)
|
||||||
) or 10);
|
) or 10);
|
||||||
|
|
||||||
my $rule = File::Find::Rule->file->name($file)
|
my $rule = File::Find::Rule
|
||||||
|
->file
|
||||||
|
->name($file)
|
||||||
->start(weechat::config_get_plugin('dir'));
|
->start(weechat::config_get_plugin('dir'));
|
||||||
|
|
||||||
if ($find) {
|
if ($find) {
|
||||||
weechat::print($buffer, " \t$_") while defined( $_ = $rule->match );
|
my $i = weechat::config_get_plugin('find_limit');
|
||||||
|
weechat::print($buffer, " \t$_")
|
||||||
|
while defined( $_ = $rule->match ) and --$i;
|
||||||
|
weechat::print($buffer, weechat::prefix('error').
|
||||||
|
"Too many results; please narrow your search") unless $i;
|
||||||
weechat::print($buffer, " \tEnd of file listing for '$file'");
|
weechat::print($buffer, " \tEnd of file listing for '$file'");
|
||||||
return weechat::WEECHAT_RC_OK;
|
return weechat::WEECHAT_RC_OK;
|
||||||
}
|
}
|
||||||
@ -112,7 +120,10 @@ sub cmd_play {
|
|||||||
if ($file =~ m"/") { $path = weechat::config_get_plugin('dir')."/$file" }
|
if ($file =~ m"/") { $path = weechat::config_get_plugin('dir')."/$file" }
|
||||||
else { $path = $rule->match }
|
else { $path = $rule->match }
|
||||||
|
|
||||||
if ($path and open FH, "<", $path) {
|
if ($path and -z $path) {
|
||||||
|
weechat::print($buffer, weechat::prefix('error').
|
||||||
|
"File '$file' is empty");
|
||||||
|
} elsif ($path and open FH, "<", $path) {
|
||||||
my @lines;
|
my @lines;
|
||||||
while (<FH>) {
|
while (<FH>) {
|
||||||
no warnings; # sprintf barks if there's nothing to replace
|
no warnings; # sprintf barks if there's nothing to replace
|
||||||
|
Loading…
Reference in New Issue
Block a user