diff --git a/.gitignore b/.gitignore index 026b96e..d96ad98 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .obsidian/wokspace.json -.obsidian/wokspace-mobile.json \ No newline at end of file +.obsidian/wokspace-mobile.json +.env diff --git a/.obsidian/workspace.json b/.obsidian/workspace.json index 4564f24..dea1fe1 100644 --- a/.obsidian/workspace.json +++ b/.obsidian/workspace.json @@ -158,8 +158,9 @@ "dbfolder:Create a new database table": false } }, - "active": "772303a551e0940a", + "active": "230c77af3893ffdd", "lastOpenFiles": [ + "igdb", "games/Castlevania symphony of the Night.md", "projects/games.md", "games/the-elder-scrolls-v-skyrim.md", @@ -186,7 +187,6 @@ "projects/todos-notes/Improve dev tools.md", "projects/todos-notes/Improve VPN setup.md", "projects/todos-notes/Setup notification services.md", - "projects/todos-notes/Rewrite neovim config.md", "projects/homelab-notes/Untitled", "projects/todos-notes", "notes/utils", diff --git a/.utils/igdb.sh b/.utils/igdb.sh new file mode 100755 index 0000000..85d0c1b --- /dev/null +++ b/.utils/igdb.sh @@ -0,0 +1,40 @@ +#!/usr/bin/env bash + +query="$*" +shift + +set -e pipefile + +if [[ -z "$query" ]]; then + echo "No query provided" + exit 1 +fi + +source "$(git rev-parse --show-toplevel)/.env" + +# login +if [[ -e /tmp/igdb-login.json ]]; then + token=$(jq -r '.access_token' /tmp/igdb-login.json) +else + login_url="https://id.twitch.tv/oauth2/token?client_id=$CLIENT_ID&client_secret=$CLIENT_SECRET&grant_type=client_credentials" + token=$(curl -s -X POST "$login_url" | tee /tmp/igdb-login.json | jq -r '.access_token') +fi + +if [[ "$token" == "null" ]]; then + echo "Couldn't fetch token" + exit 1 +fi + +fields="name, parent_game.name, franchises.name, franchises.slug, genres.name, platforms.name, release_dates.human" +limit=50 + +preview=".[{n}] | del(.id) | walk(if type == \"array\" then map((.name // .human)?) else . end )" +# preview=".[{n}]" + +curl -s 'https://api.igdb.com/v4/games' \ + -H "Client-ID: $CLIENT_ID" \ + -H "Authorization: Bearer $token" \ + -H 'Accept: application/json' \ + -d "search \"$query\"; fields $fields; where category = (0, 8, 9, 11, 13); limit $limit;" | tee /tmp/igdb-query.json | + jq -r '.[].name' | + fzf --preview "jq --sort-keys --color-output '$preview' /tmp/igdb-query.json"