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 new file mode 100644 index 0000000..0060300 --- /dev/null +++ b/zsh/.config/zsh/config.d/00_query_pk_front_color.zsh @@ -0,0 +1,14 @@ +# fetches the color of the currently fronting PK member +function fetch_fronter_color { + [ -n "$PLURALKIT_API_TOKEN" ] || return 1 + [ -n "$PLURALKIT_SYSTEM_ID" ] || return 1 + 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" +} + +# fetch the fronter color every precmd and export it for the prompt +precmd_functions+="set_fronter_color" +function set_fronter_color { + export fronter_color="$(eval_with_secrets fetch_fronter_color)" +} diff --git a/zsh/.config/zsh/config.d/00_secrets.zsh b/zsh/.config/zsh/config.d/00_secrets.zsh new file mode 100644 index 0000000..780b651 --- /dev/null +++ b/zsh/.config/zsh/config.d/00_secrets.zsh @@ -0,0 +1,5 @@ +function eval_with_secrets { + PLURALKIT_API_TOKEN="" \ + PLURALKIT_SYSTEM_ID="" \ + eval $@ +} diff --git a/zsh/.config/zsh/config.d/30_prompt.zsh b/zsh/.config/zsh/config.d/30_prompt.zsh index bb6eb82..eb9df19 100644 --- a/zsh/.config/zsh/config.d/30_prompt.zsh +++ b/zsh/.config/zsh/config.d/30_prompt.zsh @@ -9,7 +9,7 @@ autoload -Uz vcs_info precmd_functions+="vcs_info" # Prompt shows hostname if connected to a remote or if root -PROMPT="%B$([ -n "$is_remote" ] || [ "$EUID" = 0 ] && echo "%F{magenta}%m%f ")%F{$([ "$EUID" = 0 ] && echo "red" || echo "cyan")}%n%f %F{blue}%~%f%b \${vcs_info_msg_0_}%B%#%b " +PROMPT="%B$([ -n "$is_remote" ] || [ "$EUID" = 0 ] && echo "%F{magenta}%m%f ")%F{$([ "$EUID" = 0 ] && echo "red" || echo "\${fronter_color:-cyan}")}%n%f %F{blue}%~%f%b \${vcs_info_msg_0_}%B%#%b " # The line before the prompt is used by RPROMPT for information about the previous command - leave space NEWLINE=$'\n'