Skip to content

Instantly share code, notes, and snippets.

@bduggan
Created September 17, 2018 13:49
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 bduggan/144ae1158f5096fafdf58e1f85a8adde to your computer and use it in GitHub Desktop.
Save bduggan/144ae1158f5096fafdf58e1f85a8adde to your computer and use it in GitHub Desktop.
quick p6 doc
#!/usr/bin/env perl6
use JSON::Fast;
sub MAIN($term) {
my $got = %*ENV<HOME>.IO.child('.p6index.json') or do
shell 'curl https://docs.perl6.org/js/search.js?v=3 > ~/.p6index.json';
my $js = $got.slurp.subst( /^ .* 'var items ='/, '' )
.subst(/';'\s* 'var results =' .* $/, '' )
.subst('category:','"category":',:g)
.subst('value:','"value":',:g)
.subst('url:','"url":',:g)
;
my $data = from-json($js);
my @matches = $data.grep({ .<value> ~~ /:i $term /}) or exit note "no matches";
for @matches {
say ++$ ~ ": {.<value>} ( {.<category>} )"
}
my $which = prompt "Choose: ";
my $url = 'https://docs.perl6.org' ~ trim(@matches[$which-1]<url>);
shell "lynx $url";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment