1
0
Fork 0
mirror of https://github.com/romkatv/powerlevel10k.git synced 2024-12-22 07:11:58 +00:00

speed up pyenv prompt

This commit is contained in:
romkatv 2019-05-22 11:55:42 +02:00
parent 743b7c6584
commit 4a3b62cde9

View file

@ -1982,24 +1982,46 @@ prompt_virtualenv() {
fi fi
} }
function _p9k_read_pyenv_version_file() {
[[ -r $1 ]] || return
local content
read -rd $'\0' content <$1 2>/dev/null
_P9K_RETVAL=${${(j.:.)${(@)${=content}#python-}:-system}}
}
function _p9k_pyenv_global_version() {
_p9k_read_pyenv_version_file ${PYENV_ROOT:-$HOME/.pyenv}/version || _P9K_RETVAL=system
}
################################################################ ################################################################
# Segment to display pyenv information # Segment to display pyenv information
# https://github.com/pyenv/pyenv#choosing-the-python-version # https://github.com/pyenv/pyenv#choosing-the-python-version
set_default POWERLEVEL9K_PYENV_PROMPT_ALWAYS_SHOW false set_default POWERLEVEL9K_PYENV_PROMPT_ALWAYS_SHOW false
prompt_pyenv() { prompt_pyenv() {
if [[ -n "$PYENV_VERSION" ]]; then local v=${(j.:.)${(@)${(s.:.)PYENV_VERSION}#python-}}
"$1_prompt_segment" "$0" "$2" "blue" "$DEFAULT_COLOR" 'PYTHON_ICON' 0 '' "${PYENV_VERSION//\%/%%}" if [[ -z $v ]]; then
elif [ $commands[pyenv] ]; then [[ $PYENV_DIR == /* ]] && local dir=$PYENV_DIR || local dir="$PWD/$PYENV_DIR"
local pyenv_version_name="$(pyenv version-name)" while true; do
local pyenv_global="system" if _p9k_read_pyenv_version_file $dir/.python-version; then
local pyenv_root="$(pyenv root)" v=$_P9K_RETVAL
if [[ -f "${pyenv_root}/version" ]]; then break
pyenv_global="$(pyenv version-file-read ${pyenv_root}/version)"
fi fi
if [[ "${pyenv_version_name}" != "${pyenv_global}" || "${POWERLEVEL9K_PYENV_PROMPT_ALWAYS_SHOW}" == "true" ]]; then if [[ $dir == / ]]; then
"$1_prompt_segment" "$0" "$2" "blue" "$DEFAULT_COLOR" 'PYTHON_ICON' 0 '' "${pyenv_version_name//\%/%%}" [[ $POWERLEVEL9K_PYENV_PROMPT_ALWAYS_SHOW == true ]] || return
_p9k_pyenv_global_version
v=$_P9K_RETVAL
break
fi fi
dir=${dir:h}
done
fi fi
if [[ $POWERLEVEL9K_PYENV_PROMPT_ALWAYS_SHOW == false ]]; then
_p9k_pyenv_global_version
[[ $v == $_P9K_RETVAL ]] && return
fi
"$1_prompt_segment" "$0" "$2" "blue" "$DEFAULT_COLOR" 'PYTHON_ICON' 0 '' "${v//\%/%%}"
} }
################################################################ ################################################################