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
Changes from 1 commit
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
13 changes: 12 additions & 1 deletion themes/robbyrussell/robbyrussell.theme.bash
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,19 @@ 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}")) "
fi
[[ -n "${python_venv}" ]] && echo "${python_venv}"
}
petarnikolovski marked this conversation as resolved.
Show resolved Hide resolved

function prompt_command() {
PS1="${bold_green}➜ ${bold_cyan}\W${reset_color}$(scm_prompt_info)${normal} "
PS1="$(venv_prompt)${bold_green}➜ ${bold_cyan}\W${reset_color}$(scm_prompt_info)${normal} "
Copy link
Contributor

Choose a reason for hiding this comment

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

It feels a little too opinionated to place the venv_prompt even before the ... not sure if before scm_prompt_info or after it is better, but I'm leaning toward after ...

Copy link
Author

Choose a reason for hiding this comment

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

Hi, venv_prompt was usually on the leftmost side of the P1 by default with virtualenv, pipenv, and pyenv. robbyrussell theme from oh-my-zsh implements it also on the leftmost side before the .

Copy link
Author

Choose a reason for hiding this comment

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

@davidpfarrell Is there another way to modify the prompt of the theme, without changing the original theme? Because, original theme is not showing virtualenv prompt, can it be overriden through the .bashrc? Or leave somehow up to the underlying venv to modify prompt with their default (but theme seems to just ignores venv modifications of PS1 - don't know why).

Copy link
Contributor

Choose a reason for hiding this comment

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

@petarnikolovski, as it stands now most themes overwrite $PS1 before displaying every prompt. Modifications to $PS1 are just entirely lost immediately after setting them. Something like the PowerLine theme(s) allow for a lot more fine tuning, but that requires using one of those themes.

Copy link
Author

Choose a reason for hiding this comment

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

@davidpfarrell I've checked virtualenv activate script, and it places the prompt on the leftmost side:

mkdir /tmp/project
cd /tmp/project
python3 -m venv env
cat env/bin/activate

...
if [ -z "${VIRTUAL_ENV_DISABLE_PROMPT:-}" ] ; then
    _OLD_VIRTUAL_PS1="${PS1:-}"
    if [ "x(env) " != x ] ; then
	PS1="(env) ${PS1:-}"
    else
    if [ "`basename \"$VIRTUAL_ENV\"`" = "__" ] ; then
        # special case for Aspen magic directories
        # see http://www.zetadev.com/software/aspen/
        PS1="[`basename \`dirname \"$VIRTUAL_ENV\"\``] $PS1"
    else
        PS1="(`basename \"$VIRTUAL_ENV\"`)$PS1"
    fi
    fi
    export PS1
fi
...

}

PROMPT_COMMAND=prompt_command