Created
September 17, 2018 13:49
-
-
Save bduggan/144ae1158f5096fafdf58e1f85a8adde to your computer and use it in GitHub Desktop.
quick p6 doc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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