47 lines
1.6 KiB
Bash
47 lines
1.6 KiB
Bash
#!/usr/bin/env bash
|
|
|
|
# --- OPTIONS ---
|
|
declare -r NIXPKGS_PATH="$HOME/nixpkgs"
|
|
# See https://git.pvv.ntnu.no/oysteikt/nixpkgs-meta-dump
|
|
declare -r METADUMP="$(pwd)/result"
|
|
# ---------------
|
|
|
|
declare -r JQ_TRANSFORMATION='
|
|
[to_entries[]
|
|
| select (.value.changelog == null)
|
|
| { name: .key, url: .value.homepage, pos: .value.position }]
|
|
| map(select(.url != null))
|
|
| map(select(.url|type == "string"))
|
|
| map(select(.url | test("^https?://github.com.*")))
|
|
| .[].url |= sub("^https?://github.com/(?<x>.+/.+/?).*"; "\(.x)")
|
|
| .[]
|
|
'
|
|
|
|
declare -r RESULT=$(jq -c <"$METADUMP" "$JQ_TRANSFORMATION")
|
|
declare -r FZF_PREVIEW_COMMAND="
|
|
echo {} \
|
|
| jq -r '.url | \"repos/\\(.)\/releases\"' \
|
|
| xargs gh api \
|
|
| jq -r '[.[].body] | join(\"\n---------------------------------------------------------------------------\n\")'
|
|
"
|
|
|
|
CHOSEN_ENTRY=$(fzf <<<"$RESULT" --preview "$FZF_PREVIEW_COMMAND")
|
|
|
|
if [ "$CHOSEN_ENTRY" == "" ]; then
|
|
exit 0
|
|
fi
|
|
|
|
declare -r PACKAGE_URL_PIECE=$(jq -r '.url' <<<"$CHOSEN_ENTRY")
|
|
declare -r NIXPKGS_REL_POSITION=$(jq -r '.pos' <<<"$CHOSEN_ENTRY" | sed -E -s 's|/nix/store/[0-9a-z]+-source/(.+?):[[:digit:]]+|\1|')
|
|
declare -r NIXPKGS_POSITION="$NIXPKGS_PATH/$NIXPKGS_REL_POSITION"
|
|
|
|
# Determine whether finalattrs or rec (or nothing atm)
|
|
# This could use some more work
|
|
if grep -q "finalAttrs" "$NIXPKGS_POSITION"; then
|
|
export NVIM_CLIPBOARD="changelog = \"https://github.com/${PACKAGE_URL_PIECE}/releases/tag/\${finalAttrs.src.rev}\";"
|
|
else
|
|
export NVIM_CLIPBOARD="changelog = \"https://github.com/${PACKAGE_URL_PIECE}/releases/tag/\${src.rev}\";"
|
|
fi
|
|
|
|
nvim "$NIXPKGS_POSITION"
|