I'm struggling with zsh prompt, trying to convert my bash prompt to zsh hooks.
This code should display the current kerberos ticket and update accordingly, but colors don't work, neither does the update:
# initialize advanced prompt
autoload -U promptinit && promptinit
# allow functions in prompt
setopt prompt_subst
#initialize colors
autoload -U colors && colors
# add the add-zsh-hook command
autoload add-zsh-hook
# Configure History
setopt hist_ignore_all_dups
setopt inc_append_history
export HISTIGNORE="history"
source $HOME/.zsh/prompt_krb.zsh
update_krb_env() {
if [ "`which klist 2>/dev/null`" != "" ]; then
# got kerberos support installed
ticket=`klist 2>/dev/null | grep "Principal:" | sed 's/.*Principal:\ //'`;
klist -s
if [ $? -eq 0 ]; then
__KRB_PROMPT="%{$fg_no_bold['green']%}krb id \"$ticket\"";
else
if [ "$ticket" != "" ]; then
__KRB_PROMPT="%{$fg_no_bold['orange']%}expired krb id \"$ticket\"";
else
__KRB_PROMPT="%{$fg_no_bold['yellow']%}no krb id";
fi
fi
else
__KRB_PROMPT="%{$fg_no_bold['yellow']%}no krb id";
fi
_KRB_PROMPT="${__KRB_PROMPT}%{$reset_color%}";
}
krb_hook_preexec() {
case "$2" in
kinit*|kdestroy*)
__EXECUTED_KRB_CMD=1;
;;
esac
}
krb_hook_postexec() {
if [ -n "$__EXECUTED_KRB_CMD" ]; then
update_krb_env;
unset __EXECUTED_KRB_CMD;
fi
}
add-zsh-hook preexec krb_hook_preexec
add-zsh-hook precmd krb_hook_postexec
update_krb_env;
get_krb() {
echo -n $__KRB_PROMPT;
}
PROMPT="$(get_krb) >"
I have been looking into multiple tutorials, trying to build upon the code, but I seem to be missing something.