zsh: change prompt color based on current fronter
This commit is contained in:
parent
9a730a128b
commit
336b99ac32
14
zsh/.config/zsh/config.d/00_query_pk_front_color.zsh
Normal file
14
zsh/.config/zsh/config.d/00_query_pk_front_color.zsh
Normal file
|
@ -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)"
|
||||
}
|
5
zsh/.config/zsh/config.d/00_secrets.zsh
Normal file
5
zsh/.config/zsh/config.d/00_secrets.zsh
Normal file
|
@ -0,0 +1,5 @@
|
|||
function eval_with_secrets {
|
||||
PLURALKIT_API_TOKEN="" \
|
||||
PLURALKIT_SYSTEM_ID="" \
|
||||
eval $@
|
||||
}
|
|
@ -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'
|
||||
|
|
Loading…
Reference in a new issue