From 5be0914b6e6f69b9ac5d76a87dbad2c72e6d527f Mon Sep 17 00:00:00 2001 From: Jacob Pipkin Date: Thu, 31 May 2012 16:37:30 -0500 Subject: added -i option to sbofind to display .info contents --- sbofind | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/sbofind b/sbofind index dc394b5..12a07fc 100755 --- a/sbofind +++ b/sbofind @@ -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"); } -- cgit v1.2.3