speed up user and context

pull/111/head
romkatv 5 years ago
parent 921f9e664a
commit 0274263b96

@ -594,7 +594,9 @@ set_default POWERLEVEL9K_ALWAYS_SHOW_CONTEXT false
set_default POWERLEVEL9K_ALWAYS_SHOW_USER false set_default POWERLEVEL9K_ALWAYS_SHOW_USER false
set_default POWERLEVEL9K_CONTEXT_TEMPLATE "%n@%m" set_default POWERLEVEL9K_CONTEXT_TEMPLATE "%n@%m"
prompt_context() { prompt_context() {
local content if ! _p9k_cache_get $0; then
local -i enabled=1
local content='' state=''
if [[ $POWERLEVEL9K_ALWAYS_SHOW_CONTEXT == true || -z $DEFAULT_USER || -n $SSH_CLIENT || -n $SSH_TTY ]]; then if [[ $POWERLEVEL9K_ALWAYS_SHOW_CONTEXT == true || -z $DEFAULT_USER || -n $SSH_CLIENT || -n $SSH_TTY ]]; then
content=$POWERLEVEL9K_CONTEXT_TEMPLATE content=$POWERLEVEL9K_CONTEXT_TEMPLATE
else else
@ -604,24 +606,30 @@ prompt_context() {
elif [[ $POWERLEVEL9K_ALWAYS_SHOW_USER == true ]]; then elif [[ $POWERLEVEL9K_ALWAYS_SHOW_USER == true ]]; then
content="${user//\%/%%}" content="${user//\%/%%}"
else else
return enabled=0
fi fi
fi fi
local current_state="DEFAULT" if (( enabled )); then
state="DEFAULT"
if [[ "${(%):-%#}" == '#' ]]; then if [[ "${(%):-%#}" == '#' ]]; then
current_state="ROOT" state="ROOT"
elif [[ -n "$SSH_CLIENT" || -n "$SSH_TTY" ]]; then elif [[ -n "$SSH_CLIENT" || -n "$SSH_TTY" ]]; then
if [[ -n "$SUDO_COMMAND" ]]; then if [[ -n "$SUDO_COMMAND" ]]; then
current_state="REMOTE_SUDO" state="REMOTE_SUDO"
else else
current_state="REMOTE" state="REMOTE"
fi fi
elif [[ -n "$SUDO_COMMAND" ]]; then elif [[ -n "$SUDO_COMMAND" ]]; then
current_state="SUDO" state="SUDO"
fi
fi fi
"$1_prompt_segment" "${0}_${current_state}" "$2" "$DEFAULT_COLOR" yellow '' 0 '' "${content}" _p9k_cache_set "$enabled" "$state" "$content"
fi
(( _P9K_CACHE_VAL[1] )) || return
"$1_prompt_segment" "$0_$_P9K_CACHE_VAL[2]" "$2" "$DEFAULT_COLOR" yellow '' 0 '' "$_P9K_CACHE_VAL[3]"
} }
################################################################ ################################################################
@ -629,15 +637,19 @@ prompt_context() {
# Note that if $DEFAULT_USER is not set, this prompt segment will always print # Note that if $DEFAULT_USER is not set, this prompt segment will always print
set_default POWERLEVEL9K_USER_TEMPLATE "%n" set_default POWERLEVEL9K_USER_TEMPLATE "%n"
prompt_user() { prompt_user() {
if ! _p9k_cache_get $0 $1 $2; then
local user=$(whoami) local user=$(whoami)
[[ $POWERLEVEL9K_ALWAYS_SHOW_USER != true && $user == $DEFAULT_USER ]] && return if [[ $POWERLEVEL9K_ALWAYS_SHOW_USER != true && $user == $DEFAULT_USER ]]; then
if [[ "${(%):-%#}" == '#' ]]; then _p9k_cache_set true
"$1_prompt_segment" "${0}_ROOT" "$2" "${DEFAULT_COLOR}" yellow ROOT_ICON 0 '' "${POWERLEVEL9K_USER_TEMPLATE}" elif [[ "${(%):-%#}" == '#' ]]; then
_p9k_cache_set "$1_prompt_segment" "${0}_ROOT" "$2" "${DEFAULT_COLOR}" yellow ROOT_ICON 0 '' "${POWERLEVEL9K_USER_TEMPLATE}"
elif [[ -n "$SUDO_COMMAND" ]]; then elif [[ -n "$SUDO_COMMAND" ]]; then
"$1_prompt_segment" "${0}_SUDO" "$2" "${DEFAULT_COLOR}" yellow SUDO_ICON 0 '' "${POWERLEVEL9K_USER_TEMPLATE}" _p9k_cache_set "$1_prompt_segment" "${0}_SUDO" "$2" "${DEFAULT_COLOR}" yellow SUDO_ICON 0 '' "${POWERLEVEL9K_USER_TEMPLATE}"
else else
"$1_prompt_segment" "${0}_DEFAULT" "$2" "${DEFAULT_COLOR}" yellow USER_ICON 0 '' "${user//\%/%%}" _p9k_cache_set "$1_prompt_segment" "${0}_DEFAULT" "$2" "${DEFAULT_COLOR}" yellow USER_ICON 0 '' "${user//\%/%%}"
fi
fi fi
"$_P9K_CACHE_VAL[@]"
} }
################################################################ ################################################################

Loading…
Cancel
Save