From cc2e8a87f9d303c10e668c26f02379c83885b855 Mon Sep 17 00:00:00 2001 From: Jack Date: Mon, 27 Dec 2021 11:05:54 +0800 Subject: [PATCH] themes/font: Add conda python venv prompt --- themes/font/font.theme.sh | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/themes/font/font.theme.sh b/themes/font/font.theme.sh index c691e57..0361d46 100644 --- a/themes/font/font.theme.sh +++ b/themes/font/font.theme.sh @@ -37,12 +37,24 @@ THEME_CLOCK_FORMAT=${THEME_CLOCK_FORMAT:-"%I:%M:%S"} VIRTUALENV_THEME_PROMPT_PREFIX='(' VIRTUALENV_THEME_PROMPT_SUFFIX=') ' +function _python_venv_prompt { + local python_venv="" + + if [[ -n "${CONDA_DEFAULT_ENV}" ]]; then + python_venv="${CONDA_DEFAULT_ENV}" + elif [[ -n "${VIRTUAL_ENV}" ]]; then + python_venv=$(basename "${VIRTUAL_ENV}") + fi + + [[ -n "${python_venv}" ]] && echo -e "$VIRTUALENV_THEME_PROMPT_PREFIX$python_venv$VIRTUALENV_THEME_PROMPT_SUFFIX" +} + function prompt_command() { # This needs to be first to save last command return code local RC="$?" hostname="${bold_black}\u@\h" - virtualenv="${white}$(virtualenv_prompt)" + virtualenv="${white}$(_python_venv_prompt)" # Set return status color if [[ ${RC} == 0 ]]; then