-
-
Save toyboot4e/4f45136c4724bd09b3150664f3e2d91e to your computer and use it in GitHub Desktop.
This file contains 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 bash -euE | |
# NOTE: Use cached version of curl | |
# TODO: Just search from local haskell reposiotory :( | |
word="$1" | |
url="$(hoogle search --json -n1 "$word" | jq .[].url | sed 's;";;g')" | |
base_url="$(printf '%s' "$url" | sed -E 's;(.*/).*;\1;g')" | |
# echo "$url" | |
# echo "$base_url" | |
relative_url="$(curl "$url" -L -s | pup ":parent-of(a[href=#v:$word])" | pup '.link attr{href}')" | |
source_url="$(printf '%s/%s' "$base_url" "$relative_url")" | |
# echo "$relative_url" | |
# echo "$source_url" | |
source="$( | |
curl "$source_url" -L -s | | |
html2text | | |
tail -n +2 # remove XML tag | |
)" | |
printf '%s' "$source" | bat -l haskell --pager "less -RF --pattern=$word.*::" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment