Skip to content

Instantly share code, notes, and snippets.

@b2gills
Last active July 13, 2017 16:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save b2gills/089854ad236635279ec7ff416e585f7a to your computer and use it in GitHub Desktop.
Save b2gills/089854ad236635279ec7ff416e585f7a to your computer and use it in GitHub Desktop.
Search FreeBSD ports tree
use v6;
unit class PortUtils::Search;
has IO::Path $.ports-dir;
has IO::Path @.cats;
method new() {
my $ports-dir = '/usr/ports/'.IO;
my IO::Path @cats;
my @check = $ports-dir;
while @check {
my $check = shift @check;
@check.append: @cats.append: $check.dir.grep: *.d
}
return self.bless( :$ports-dir, :@cats );
}
proto method query ( \query ) {*}
multi method query ( Str \query ) {
@.cats.grep(*.basename.contains(query))».relative($.ports-dir)
}
multi method query ( Callable \query ) { # also handles Regex
@.cats.grep(query)».relative($.ports-dir)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment