Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add virtualenv prompt for robbyrussell theme #2060

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions themes/base.theme.bash
Original file line number Diff line number Diff line change
Expand Up @@ -625,3 +625,14 @@ function _save-and-reload-history() {
local autosave=${1:-0}
[[ $autosave -eq 1 ]] && history -a && history -c && history -r
}

function conda_or_venv_prompt() {
local python_venv=""
if [[ -n "${CONDA_DEFAULT_ENV:-}" ]]; then
python_venv=$(condaenv_prompt)
PYTHON_VENV_CHAR=${CONDA_PYTHON_VENV_CHAR}
elif [[ -n "${VIRTUAL_ENV:-}" ]]; then
python_venv=$(virtualenv_prompt)
fi
[[ -n "${python_venv}" ]] && echo "${PYTHON_VENV_CHAR}${python_venv}"
}
Comment on lines +629 to +638
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function should probably live closer to the existing functions.

NOTE: PYTHON_VENV_CHAR and CONDA_PYTHON_VENV_CHAR are only used by the themes that do not invoke the virtualenv_prompt or condaenv_prompt functions. Those function use PYTHON_THEME_PROMPT_PREFIX and PYTHON_THEME_PROMPT_SUFFIX

The spirit of the methods that live in this base theme is to use the PREFIX and SUFFIX variables.

I think this function just becomes:

	if [[ -n "${CONDA_DEFAULT_ENV:-}" ]]; then
		condaenv_prompt
	elif [[ -n "${VIRTUAL_ENV:-}" ]]; then
		virtualenv_prompt
	fi

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi @petarnikolovski, want to continue and improve this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@NoahGorny Sorry for the late response, I will make moves on improvement soon, I couldn't manage because of my work schedule.

5 changes: 4 additions & 1 deletion themes/robbyrussell/robbyrussell.theme.bash
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@ GIT_THEME_PROMPT_SUFFIX="${bold_blue})"
RVM_THEME_PROMPT_PREFIX="|"
RVM_THEME_PROMPT_SUFFIX="|"

VIRTUALENV_THEME_PROMPT_PREFIX='('
VIRTUALENV_THEME_PROMPT_SUFFIX=') '

function git_prompt_info() {
git_prompt_vars
echo -e "$SCM_PREFIX${bold_red}$SCM_BRANCH$SCM_STATE$SCM_SUFFIX"
}

function prompt_command() {
PS1="${bold_green}➜ ${bold_cyan}\W${reset_color}$(scm_prompt_info)${normal} "
PS1="$(conda_or_venv_prompt)${bold_green}➜ ${bold_cyan}\W${reset_color}$(scm_prompt_info)${normal} "
}

PROMPT_COMMAND=prompt_command