Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?

oh-my-zsh::plugin::virtualenv-prompt

This is a fork of the virtualenv plugin from upstream. It support to customize the virtualenv prompt in oh-my-zsh themes.

Installation

You can install this plugin quickly via curl:

curl -L https://raw.github.com/tonyseek/oh-my-zsh-virtualenv-prompt/master/install.sh | sh

Or via wget:

wget https://raw.github.com/tonyseek/oh-my-zsh-virtualenv-prompt/master/install.sh -O - | sh

Or you can install from shell by yourself also:

repo="git://github.com/tonyseek/oh-my-zsh-virtualenv-prompt.git"
target="$HOME/.oh-my-zsh/plugins/virtualenv-prompt"

git clone $repo $target

Customize Theme

There are two constant strings which could be overrided in your custom theme.

  • ZSH_THEME_VIRTUAL_ENV_PROMPT_PREFIX
  • ZSH_THEME_VIRTUAL_ENV_PROMPT_SUFFIX

And the function virtualenv_prompt_info could be used in the prompt of your theme.

Example

See the oh-my-zsh::theme::seeker.

#!/usr/bin/env sh
set -e
repo="git://github.com/tonyseek/oh-my-zsh-virtualenv-prompt.git"
target="$HOME/.oh-my-zsh/plugins/virtualenv-prompt"
if [ -d "$target" ]; then
if [ -d "$target/.git" ]; then
(cd $target && git pull --ff-only origin master)
fi
else
git clone $repo $target
fi
export VIRTUAL_ENV_DISABLE_PROMPT=1
ZSH_THEME_VIRTUAL_ENV_PROMPT_PREFIX="("
ZSH_THEME_VIRTUAL_ENV_PROMPT_SUFFIX=")"
function virtualenv_prompt_info() {
if [ -n "$VIRTUAL_ENV" ]; then
if [ -f "$VIRTUAL_ENV/__name__" ]; then
local name=`cat $VIRTUAL_ENV/__name__`
elif [ `basename $VIRTUAL_ENV` = "__" ]; then
local name=$(basename $(dirname $VIRTUAL_ENV))
else
local name=$(basename $VIRTUAL_ENV)
fi
echo "$ZSH_THEME_VIRTUAL_ENV_PROMPT_PREFIX$name$ZSH_THEME_VIRTUAL_ENV_PROMPT_SUFFIX"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.