diff --git a/themes/base.theme.bash b/themes/base.theme.bash index a7e999617b..881f4aaa64 100644 --- a/themes/base.theme.bash +++ b/themes/base.theme.bash @@ -587,3 +587,14 @@ function _save-and-reload-history() { local autosave=${1:-0} [[ $autosave -eq 1 ]] && history -a && history -c && history -r } + +function venv_prompt() { + local python_venv="" + if [[ -n "${CONDA_DEFAULT_ENV:-}" ]]; then + python_venv="${CONDA_DEFAULT_ENV}" + PYTHON_VENV_CHAR=${CONDA_PYTHON_VENV_CHAR} + elif [[ -n "${VIRTUAL_ENV:-}" ]]; then + python_venv="${VIRTUAL_ENV##*/}" + fi + [[ -n "${python_venv}" ]] && echo "${PYTHON_VENV_CHAR}${python_venv}" +} diff --git a/themes/robbyrussell/robbyrussell.theme.bash b/themes/robbyrussell/robbyrussell.theme.bash index 8f7ffb334b..23fc885d55 100644 --- a/themes/robbyrussell/robbyrussell.theme.bash +++ b/themes/robbyrussell/robbyrussell.theme.bash @@ -18,19 +18,16 @@ function git_prompt_info() { echo -e "$SCM_PREFIX${bold_red}$SCM_BRANCH$SCM_STATE$SCM_SUFFIX" } -function venv_prompt() { - python_venv="" - # Detect python venv - if [[ -n "${CONDA_DEFAULT_ENV}" ]]; then - python_venv="($PYTHON_VENV_CHAR${CONDA_DEFAULT_ENV}) " - elif [[ -n "${VIRTUAL_ENV}" ]]; then - python_venv="($PYTHON_VENV_CHAR$(basename "${VIRTUAL_ENV}")) " +function venv_parenthases() { + if [[ $(venv_prompt) != "" ]]; then + echo "($(venv_prompt)) " + else + echo "" fi - [[ -n "${python_venv}" ]] && echo "${python_venv}" } function prompt_command() { - PS1="$(venv_prompt)${bold_green}➜ ${bold_cyan}\W${reset_color}$(scm_prompt_info)${normal} " + PS1="$(venv_parenthases)${bold_green}➜ ${bold_cyan}\W${reset_color}$(scm_prompt_info)${normal} " } PROMPT_COMMAND=prompt_command