Skip to content

Instantly share code, notes, and snippets.

@josejaguirre
Created May 25, 2017 22:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save josejaguirre/f46821f52a9e8955135e8928b9c5aa5b to your computer and use it in GitHub Desktop.
Save josejaguirre/f46821f52a9e8955135e8928b9c5aa5b to your computer and use it in GitHub Desktop.

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