Skip to content

Instantly share code, notes, and snippets.

@toyboot4e

toyboot4e/h Secret

Last active June 10, 2022 23: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 toyboot4e/4f45136c4724bd09b3150664f3e2d91e to your computer and use it in GitHub Desktop.
Save toyboot4e/4f45136c4724bd09b3150664f3e2d91e to your computer and use it in GitHub Desktop.
#!/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