Created
August 13, 2022 04:23
-
-
Save flxai/74cef808eab23cc5f4417ecfc5f34812 to your computer and use it in GitHub Desktop.
nixpkgs searches search.nixos.org for packages and prints their infos
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 bash | |
# nixpkgs queries and parses search.nixos.org in a dirty way | |
channel=22.05 | |
sort_mode=relevance | |
max_wait=10000 | |
function usage() { | |
echo "Usage:" | |
echo "$(basename ""$0"") SEARCH_TERM" | |
exit 1 | |
} | |
function bail() { | |
echo "$2" | |
exit "$1" | |
} | |
function get_html() { | |
url="https://search.nixos.org/packages?channel=${channel}&from=0&size=50&sort=${sort_mode}&type=packages&query=${1}" | |
chromium-browser \ | |
--headless \ | |
--dump-dom \ | |
--disable-gpu \ | |
--run-all-compositor-stages-before-draw \ | |
--virtual-time-budget=${max_wait} \ | |
"$url" 2>/dev/null | |
} | |
[[ $# -gt 0 ]] || usage | |
html=$(get_html "$1") | |
json=$(<<< "$html" pup .search-results li.package json{}) | |
<<< "$json" jq -e '.. | select(type == "array" and length == 0)' > /dev/null && bail 2 "Timed out... turn up max_wait?" | |
<<< "$json" jq -r '.[] | "\u001b[1;37m\(.children[2].children[0].children[0].text)\u001b[0m \u001b[37m\(.children[2].children[1].children[0].text) \u001b[1;30m\(.children[0].children[0].text)\u001b[0m \(.children[1].text)"' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment