zsh: pk shenanigans: export more things
This commit is contained in:
parent
3eeb6d8d87
commit
6061b04da4
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue