mirror of
https://github.com/ohmybash/oh-my-bash.git
synced 2024-05-11 05:55:37 +00:00
themes/agnoster: Refactor prompt_{virtual,conda}env
This commit is contained in:
@@ -212,31 +212,28 @@ function prompt_end {
|
|||||||
|
|
||||||
### virtualenv prompt
|
### virtualenv prompt
|
||||||
function prompt_virtualenv {
|
function prompt_virtualenv {
|
||||||
if [[ -n $VIRTUAL_ENV ]]; then
|
if [[ -d $VIRTUAL_ENV ]]; then
|
||||||
# Python could output the version information in both stdout and
|
# Python could output the version information in both stdout and
|
||||||
# stderr (e.g. if using pyenv, the output goes to stderr).
|
# stderr (e.g. if using pyenv, the output goes to stderr).
|
||||||
VERSION_OUTPUT=$($VIRTUAL_ENV/bin/python --version 2>&1)
|
local VERSION_OUTPUT=$("$VIRTUAL_ENV"/bin/python --version 2>&1)
|
||||||
|
|
||||||
# The last word of the output of `python --version`
|
# The last word of the output of `python --version`
|
||||||
# corresponds to the version number.
|
# corresponds to the version number.
|
||||||
VENV_VERSION=$(echo $VERSION_OUTPUT | awk '{print $NF}')
|
local VENV_VERSION=$(awk '{print $NF}' <<< "$VERSION_OUTPUT")
|
||||||
|
|
||||||
color=cyan
|
prompt_segment cyan white "[v] $(basename "$VENV_VERSION")"
|
||||||
prompt_segment $color $PRIMARY_FG
|
fi
|
||||||
prompt_segment $color white "[v] $(basename $VENV_VERSION)"
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
### conda env prompt
|
### conda env prompt
|
||||||
prompt_conda_env() {
|
function prompt_condaenv {
|
||||||
if [[ -n $CONDA_PREFIX ]]; then
|
if [[ -d $CONDA_PREFIX ]]; then
|
||||||
if [[ -z $CONDA_PROMPT_MODIFIER ]]; then
|
if [[ ! $CONDA_PROMPT_MODIFIER ]]; then
|
||||||
CONDA_PROMPT_MODIFIER=$(basename $CONDA_PREFIX)
|
CONDA_PROMPT_MODIFIER=$(basename "$CONDA_PREFIX")
|
||||||
fi
|
|
||||||
CONDA_PYTHON_VERSION=$($CONDA_PREFIX/bin/python -c 'import platform;print(platform.python_version())')
|
|
||||||
prompt_segment cyan $PRIMARY_FG
|
|
||||||
prompt_segment cyan white "[c] $CONDA_PROMPT_MODIFIER $CONDA_PYTHON_VERSION"
|
|
||||||
fi
|
fi
|
||||||
|
local CONDA_PYTHON_VERSION=$("$CONDA_PREFIX"/bin/python -c 'import platform;print(platform.python_version())')
|
||||||
|
prompt_segment cyan white "[c] $CONDA_PROMPT_MODIFIER $CONDA_PYTHON_VERSION"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
### Prompt components
|
### Prompt components
|
||||||
@@ -422,7 +419,7 @@ function build_prompt {
|
|||||||
[[ -z ${AG_NO_CONTEXT+x} ]] && prompt_context
|
[[ -z ${AG_NO_CONTEXT+x} ]] && prompt_context
|
||||||
if [[ ${OMB_PROMPT_SHOW_PYTHON_VENV-} ]]; then
|
if [[ ${OMB_PROMPT_SHOW_PYTHON_VENV-} ]]; then
|
||||||
prompt_virtualenv
|
prompt_virtualenv
|
||||||
prompt_conda_env
|
prompt_condaenv
|
||||||
fi
|
fi
|
||||||
prompt_dir
|
prompt_dir
|
||||||
prompt_git
|
prompt_git
|
||||||
|
|||||||
Reference in New Issue
Block a user