Skip to content

Commit

Permalink
Add venv prompt to base theme
Browse files Browse the repository at this point in the history
  • Loading branch information
petarnikolovski committed Jan 26, 2022
1 parent 10ead37 commit 818f095
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
11 changes: 11 additions & 0 deletions themes/base.theme.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
}
15 changes: 6 additions & 9 deletions themes/robbyrussell/robbyrussell.theme.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 818f095

Please sign in to comment.