diff options
author | Jacob Pipkin <j@dawnrazor.net> | 2012-05-31 16:37:30 -0500 |
---|---|---|
committer | Jacob Pipkin <j@dawnrazor.net> | 2012-05-31 16:37:30 -0500 |
commit | 5be0914b6e6f69b9ac5d76a87dbad2c72e6d527f (patch) | |
tree | 7afedf9f8e9691d244d0bc95da78b9dc5b4e4a6f | |
parent | 9b8bfae0b3b13566ea5b7010b8e534e33db94351 (diff) | |
download | sbotools2-5be0914b6e6f69b9ac5d76a87dbad2c72e6d527f.tar.xz |
added -i option to sbofind to display .info contents
-rwxr-xr-x | sbofind | 30 |
1 files changed, 22 insertions, 8 deletions
@@ -23,6 +23,7 @@ Usage: $self (search_term) Options: -h: this screen. -v: version information. + -i: show the .info for each found item. -r: show the README for each found item. Example: @@ -32,12 +33,13 @@ EOF } my %options; -getopts ('hvr', \%options); +getopts ('hvir', \%options); show_usage () and exit (0) if (exists $options{h}); show_version () and exit (0) if (exists $options{v}); my $show_readme = exists $options{r} ? 'TRUE' : 'FALSE'; +my $show_info = exists $options{i} ? 'TRUE' : 'FALSE'; show_usage () and exit (1) unless exists $ARGV[0]; my $search = $ARGV[0]; @@ -69,19 +71,31 @@ FIRST: while (my $line = <$sb_txt>) { } } +sub get_file_contents { + script_error ('get_file_contents requires an argument') unless exists $_[0]; + script_error ('get_file_contents argument is not a file') unless -f $_[0]; + my $file = shift; + open my $fh, '<', $file; + my $contents = do {local $/; <$fh>}; + $contents =~ s/\n/\n /g; + $contents =~ s/ $//g; + return $contents; +} + +# pretty formatting if (exists $findings[0]) { - # pretty formatting - my @listing; + my @listing = ("\n"); for my $hash (@findings) { while (my ($key, $value) = each %{$hash}) { push (@listing, "SBo: $key\n"); push (@listing, "Path: $value\n"); + if ($show_info eq 'TRUE') { + push (@listing, "info: ". get_file_contents + ("$value/$key.info") ); + } if ($show_readme eq 'TRUE') { - open my $fh, '<', "$value/README"; - my $readme = do {local $/; <$fh>}; - $readme =~ s/\n/\n /g; - push (@listing, "README: $readme"); - close $readme; + push (@listing, "README: ". get_file_contents + ("$value/README") ); } push (@listing, "\n"); } |