From 6061b04da408c7e1c61adf1c641c8be129efaac0 Mon Sep 17 00:00:00 2001 From: Erin Date: Thu, 20 Jul 2023 00:06:23 -0400 Subject: [PATCH] zsh: pk shenanigans: export more things --- .../zsh/config.d/00_query_pk_front_color.zsh | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/zsh/.config/zsh/config.d/00_query_pk_front_color.zsh b/zsh/.config/zsh/config.d/00_query_pk_front_color.zsh index 58ce219..83a7b6e 100644 --- a/zsh/.config/zsh/config.d/00_query_pk_front_color.zsh +++ b/zsh/.config/zsh/config.d/00_query_pk_front_color.zsh @@ -1,14 +1,28 @@ # fetches the color of the currently fronting PK member -function fetch_fronter_color { +function fetch_fronter_information { + # return non-zero if secrets are missing [ -n "$PLURALKIT_API_TOKEN" ] || return 1 [ -n "$PLURALKIT_SYSTEM_ID" ] || return 1 + + # fetch first current fronter from API endpoint="https://api.pluralkit.me/v2/systems/$PLURALKIT_SYSTEM_ID/fronters" - color=$(curl -sH "Authorization: $PLURALKIT_API_TOKEN" "$endpoint" | jq -r ".members[0].color // empty") - [ -n "$color" ] && echo "#$color" + response="$(curl -sH "Authorization: $PLURALKIT_API_TOKEN" "$endpoint")" + fronter="$(echo "$response" | jq -r '.members[0] // empty')" + + # return gracefully without doing anything if there is no current fronter + [ -n "$fronter" ] || return + + # export information about the fronter + export PK_FRONTER_ID="$(echo $fronter | jq -r '.id')" + export PK_FRONTER_NAME="$(echo $fronter | jq -r '.name')" + export PK_FRONTER_DISPLAY_NAME="$(echo $fronter | jq -r '.display_name')" + export PK_FRONTER_AVATAR_URL="$(echo $fronter | jq -r '.avatar_url')" + color="$(echo $response | jq -r '.members[0].color // empty')" + [ -n "$color" ] && export PK_FRONTER_COLOR="#$color" } # fetch the fronter color every precmd and export it for the prompt -precmd_functions+="set_fronter_color" -function set_fronter_color { - export PK_FRONTER_COLOR="$(eval_with_secrets fetch_fronter_color)" +precmd_functions+="set_fronter_information" +function set_fronter_information { + eval_with_secrets fetch_fronter_information }