1
0
mirror of https://github.com/dcarrillo/prezto.git synced 2024-12-22 13:58:00 +00:00

python-info: add support for pyenv and only do extra work if the prompt needs it

This commit is contained in:
Kaleb Elwert 2017-12-04 15:08:58 -08:00
parent 3a0bd28e0c
commit 3ab569ff78

View File

@ -13,29 +13,39 @@ local virtualenv_format
local virtualenv_formatted local virtualenv_formatted
local version_format local version_format
local version_formatted local version_formatted
local version
# Clean up previous $python_info. # Clean up previous $python_info.
unset python_info unset python_info
typeset -gA python_info typeset -gA python_info
# Grab the styling we might have to do
zstyle -s ':prezto:module:python:info:virtualenv' format 'virtualenv_format'
zstyle -s ':prezto:module:python:info:version' format 'version_format'
# Format virtualenv. # Format virtualenv.
if [[ -n "$VIRTUAL_ENV" ]]; then if [[ -n "$virtualenv_format" ]]; then
zstyle -s ':prezto:module:python:info:virtualenv' format 'virtualenv_format' if [[ -n "$VIRTUAL_ENV" ]]; then
zformat -f virtualenv_formatted "$virtualenv_format" "v:${VIRTUAL_ENV:t}" zformat -f virtualenv_formatted "$virtualenv_format" "v:${VIRTUAL_ENV:t}"
python_info[virtualenv]="$virtualenv_formatted" python_info[virtualenv]="$virtualenv_formatted"
fi
# Do the same for Conda virtual environments
if [[ -n "$CONDA_DEFAULT_ENV" ]]; then
zformat -f virtualenv_formatted "$virtualenv_format" "v:${CONDA_DEFAULT_ENV:t}"
python_info[virtualenv]="$virtualenv_formatted"
fi
fi fi
# Do the same for Conda virtual environments if [[ -n "$version_format" ]]; then
if [[ -n "$CONDA_DEFAULT_ENV" ]]; then if (( $+commands[pyenv] )); then
zstyle -s ':prezto:module:python:info:virtualenv' format 'virtualenv_format' version="${"$(pyenv version)"%% *}"
zformat -f virtualenv_formatted "$virtualenv_format" "v:${CONDA_DEFAULT_ENV:t}" elif (( $+commands[python] )); then
python_info[virtualenv]="$virtualenv_formatted" version="${$(python3 --version)#Python }"
fi fi
if (( $+commands[python] )); then if [[ -n "$version" && "$version" != "system" ]]; then
zstyle -s ':prezto:module:python:info:version' format 'version_format' zformat -f version_formatted "$version_format" "v:$version"
if [[ -n "$version_format" ]]; then
zformat -f version_formatted "$version_format" "v:${$(python3 --version)#Python }"
python_info[version]="$version_formatted" python_info[version]="$version_formatted"
fi fi
fi fi