diff options
author | Jacob Pipkin <d4wnr4z0r@yahoo.com> | 2012-05-08 00:44:49 -0500 |
---|---|---|
committer | Jacob Pipkin <d4wnr4z0r@yahoo.com> | 2012-05-08 00:44:49 -0500 |
commit | b7afd023a8e5ff86f751196984ba87dcb9d451cd (patch) | |
tree | 0e6add668d896be591972c4e7fb2a02b31488770 /sbofind | |
download | sbotools2-b7afd023a8e5ff86f751196984ba87dcb9d451cd.tar.xz |
initial repo add
Diffstat (limited to 'sbofind')
-rwxr-xr-x | sbofind | 85 |
1 files changed, 85 insertions, 0 deletions
@@ -0,0 +1,85 @@ +#!/usr/bin/env perl +# +# sbofind +# script to locate something in a local SlackBuilds tree. +# +# author: Jacob Pipkin <j@dawnrazor.net> +# date: Boomtime, the 39th day of Discord in the YOLD 3178 +# license: WTFPL <http://sam.zoy.org/wtfpl/COPYING> + +use SBO::Lib; +use File::Basename; +use Getopt::Std; +use Text::Tabulate; +use strict; +use warnings FATAL => 'all'; + +my %config = %SBO::Lib::config; +my $self = basename($0); + +sub show_usage { + print <<EOF +Usage: $self (search_term) + +Options: + -h: this screen. + -v: version information. + +Example: + $self libsexy + +EOF +} + +my %options; +getopts('hv',\%options); + +show_usage() and exit(0) if (exists $options{h}); +show_version() and exit(0) if (exists $options{v}); + +show_usage() and exit(1) unless exists $ARGV[0]; +my $search = $ARGV[0]; + +check_slackbuilds_txt(); + +my (@findings,$name); +my $found = 'FALSE'; +my $regex = qr/NAME:\s.*\Q$search\E.*/; +open my $sb_txt, '<', "$config{SBO_HOME}/SLACKBUILDS.TXT"; +FIRST: while (my $line = <$sb_txt>) { + unless ($found eq 'TRUE') { + if ($line =~ $regex) { + $found = 'TRUE'; + my @split = split(' ',$line); + chomp($name = $split[2]); + next FIRST; + } + } else { + if ($line =~ /LOCATION/) { + $found = 'FALSE'; + my @split = split(' ',$line); + chomp(my $location = $split[2]); + $location =~ s#^\.##; + my %hash = ($name => $config{SBO_HOME} . $location); + push(@findings,\%hash); + } + } +} + +if (exists $findings[0]) { + my @listing; + for my $hash (@findings) { + while (my ($key,$value) = each %{$hash}) { + push(@listing,"SBo: $key\n"); + push(@listing,"Path: $value\n\n"); + } + } + my $tab = new Text::Tabulate(); + $tab->configure(tab => '\s'); + my $output = $tab->format(@listing); + print "\n". $output; +} else { + print "Nothing found for search term: $search\n"; +} + +exit(0); |