speed up user and context

pull/111/head
romkatv 6 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_CONTEXT_TEMPLATE "%n@%m"
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
content=$POWERLEVEL9K_CONTEXT_TEMPLATE
else
@ -604,24 +606,30 @@ prompt_context() {
elif [[ $POWERLEVEL9K_ALWAYS_SHOW_USER == true ]]; then
content="${user//\%/%%}"
else
return
enabled=0
fi
fi
local current_state="DEFAULT"
if (( enabled )); then
state="DEFAULT"
if [[ "${(%):-%#}" == '#' ]]; then
current_state="ROOT"
state="ROOT"
elif [[ -n "$SSH_CLIENT" || -n "$SSH_TTY" ]]; then
if [[ -n "$SUDO_COMMAND" ]]; then
current_state="REMOTE_SUDO"
state="REMOTE_SUDO"
else
current_state="REMOTE"
state="REMOTE"
fi
elif [[ -n "$SUDO_COMMAND" ]]; then
current_state="SUDO"
state="SUDO"
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
set_default POWERLEVEL9K_USER_TEMPLATE "%n"
prompt_user() {
if ! _p9k_cache_get $0 $1 $2; then
local user=$(whoami)
[[ $POWERLEVEL9K_ALWAYS_SHOW_USER != true && $user == $DEFAULT_USER ]] && return
if [[ "${(%):-%#}" == '#' ]]; then
"$1_prompt_segment" "${0}_ROOT" "$2" "${DEFAULT_COLOR}" yellow ROOT_ICON 0 '' "${POWERLEVEL9K_USER_TEMPLATE}"
if [[ $POWERLEVEL9K_ALWAYS_SHOW_USER != true && $user == $DEFAULT_USER ]]; then
_p9k_cache_set true
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
"$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
"$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
"$_P9K_CACHE_VAL[@]"
}
################################################################

Loading…
Cancel
Save