Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

themes/agnoster : pyenv not properly detected/shown #458

Merged
merged 4 commits into from
Jul 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions themes/agnoster/agnoster.theme.sh
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,9 @@ function prompt_end {

### virtualenv prompt
function prompt_virtualenv {
# Exclude pyenv
[[ $PYENV_VIRTUALENV_INIT == 1 ]] && _omb_util_binary_exists pyenv && return 0

if [[ -d $VIRTUAL_ENV ]]; then
# Python could output the version information in both stdout and
# stderr (e.g. if using pyenv, the output goes to stderr).
Expand All @@ -296,6 +299,29 @@ function prompt_virtualenv {
fi
}

### pyenv prompt
function prompt_pyenv {
if [[ $PYENV_VIRTUALENV_INIT == 1 ]] && _omb_util_binary_exists pyenv; then
# Priority is shell > local > global
# When pyenv shell is set, the environment variable $PYENV_VERSION is set with the value we want
if [[ ! ${PYENV_VERSION-} ]]; then
# If not set, fall back to pyenv local/global to get the version
local PYENV_VERSION=$(pyenv local 2>/dev/null || pyenv global 2>/dev/null)
fi
# If it is not the system's python, then display additional info
if [[ "$PYENV_VERSION" != "system" ]]; then
# It's a pyenv virtualenv, get the version number
if [[ -d $PYENV_VIRTUAL_ENV ]]; then
local VERSION_OUTPUT=$("$PYENV_VIRTUAL_ENV"/bin/python --version 2>&1)
local PYENV_VENV_VERSION=$(awk '{print $NF}' <<< "$VERSION_OUTPUT")
prompt_segment cyan white "[$PYENV_VERSION] $(basename "$PYENV_VENV_VERSION")"
else
prompt_segment cyan white "$PYENV_VERSION"
fi
fi
fi
}

### conda env prompt
function prompt_condaenv {
if [[ -d $CONDA_PREFIX ]]; then
Expand Down Expand Up @@ -534,6 +560,7 @@ function build_prompt {
[[ -z ${AG_NO_CONTEXT+x} ]] && prompt_context
if [[ ${OMB_PROMPT_SHOW_PYTHON_VENV-} ]]; then
prompt_virtualenv
prompt_pyenv
prompt_condaenv
fi
prompt_dir
Expand Down
Loading