Skip to content

Commit 818f095

Browse files
Add venv prompt to base theme
1 parent 10ead37 commit 818f095

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

themes/base.theme.bash

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,3 +587,14 @@ function _save-and-reload-history() {
587587
local autosave=${1:-0}
588588
[[ $autosave -eq 1 ]] && history -a && history -c && history -r
589589
}
590+
591+
function venv_prompt() {
592+
local python_venv=""
593+
if [[ -n "${CONDA_DEFAULT_ENV:-}" ]]; then
594+
python_venv="${CONDA_DEFAULT_ENV}"
595+
PYTHON_VENV_CHAR=${CONDA_PYTHON_VENV_CHAR}
596+
elif [[ -n "${VIRTUAL_ENV:-}" ]]; then
597+
python_venv="${VIRTUAL_ENV##*/}"
598+
fi
599+
[[ -n "${python_venv}" ]] && echo "${PYTHON_VENV_CHAR}${python_venv}"
600+
}

themes/robbyrussell/robbyrussell.theme.bash

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,16 @@ function git_prompt_info() {
1818
echo -e "$SCM_PREFIX${bold_red}$SCM_BRANCH$SCM_STATE$SCM_SUFFIX"
1919
}
2020

21-
function venv_prompt() {
22-
python_venv=""
23-
# Detect python venv
24-
if [[ -n "${CONDA_DEFAULT_ENV}" ]]; then
25-
python_venv="($PYTHON_VENV_CHAR${CONDA_DEFAULT_ENV}) "
26-
elif [[ -n "${VIRTUAL_ENV}" ]]; then
27-
python_venv="($PYTHON_VENV_CHAR$(basename "${VIRTUAL_ENV}")) "
21+
function venv_parenthases() {
22+
if [[ $(venv_prompt) != "" ]]; then
23+
echo "($(venv_prompt)) "
24+
else
25+
echo ""
2826
fi
29-
[[ -n "${python_venv}" ]] && echo "${python_venv}"
3027
}
3128

3229
function prompt_command() {
33-
PS1="$(venv_prompt)${bold_green}${bold_cyan}\W${reset_color}$(scm_prompt_info)${normal} "
30+
PS1="$(venv_parenthases)${bold_green}${bold_cyan}\W${reset_color}$(scm_prompt_info)${normal} "
3431
}
3532

3633
PROMPT_COMMAND=prompt_command

0 commit comments

Comments
 (0)