29 lines
1.2 KiB
Bash
29 lines
1.2 KiB
Bash
# exports info about the currently fronting PK system member for use in prompts
|
|
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"
|
|
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_information"
|
|
function set_fronter_information {
|
|
eval_with_secrets fetch_fronter_information
|
|
}
|