aboutsummaryrefslogtreecommitdiff
path: root/mcsh.sh
diff options
context:
space:
mode:
authorCaroline Larimore <caroline@larimo.re>2025-11-27 12:33:55 -0800
committerCaroline Larimore <caroline@larimo.re>2025-11-27 12:33:55 -0800
commit5a683c455863dac52bb88af301a2f4987136c963 (patch)
tree101c81c02c21d2224617f3e6293b2fbb796f3e6b /mcsh.sh
parente16c4722335cc8ee4c198144d6c2cb20b7265ad0 (diff)
refactor: reformat profile json
Diffstat (limited to 'mcsh.sh')
-rwxr-xr-xmcsh.sh26
1 files changed, 24 insertions, 2 deletions
diff --git a/mcsh.sh b/mcsh.sh
index 26522f1..3853b4e 100755
--- a/mcsh.sh
+++ b/mcsh.sh
@@ -157,8 +157,30 @@ function update_profile (
exit 1
fi
- #TODO: hyphenate uuid, for :sparkles: style :sparkles:
- profiles="$(<<<"$res" jq --arg profile "$profile" --slurpfile profiles "$DATA_DIR/profiles.json" '$profiles[0] + {"\(.name)": $profiles[0].[$profile] + {"username": .name, "uuid": .id}} | del(.["<unknown>"])')"
+ uuid="$(<<<"$res" jq -r '.id')"
+ uuid="${uuid:0:8}-${uuid:8:4}-${uuid:12:4}-${uuid:16:4}-${uuid:20:12}"
+
+ profiles="$(
+ <<<"$res" jq \
+ --arg profile "$profile" \
+ --arg uuid "$uuid" \
+ --slurpfile profiles "$DATA_DIR/profiles.json" \
+ '$profiles[0].[$profile] as $prev
+ | $profiles[0] + {
+ "\(.name)": {
+ "username": .name,
+ "uuid": $uuid,
+ "xuid": $prev.xuid,
+ "type": $prev.type,
+ "skins": .skins,
+ "capes": .capes,
+ "refresh_token": $prev.refresh_token,
+ "xbl_token": $prev.xbl_token,
+ "mc_token": $prev.mc_token
+ }
+ }
+ | del(.["<unknown>"])'
+ )"
<<<"$profiles" cat > "$DATA_DIR/profiles.json"
jq --arg profile "$profile" '.[$profile]' "$DATA_DIR/profiles.json"