From d564b8e0f70cd3cbc88733e2921f0a77a129a1f5 Mon Sep 17 00:00:00 2001 From: Amand Tihon Date: Wed, 7 Dec 2016 11:31:14 +0100 Subject: [PATCH] Add support for virtualenv name in prompt. --- S20_env | 2 ++ S60_virtualenv | 15 +++++++++++++++ S90_prompt | 10 ++++++++-- 3 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 S60_virtualenv diff --git a/S20_env b/S20_env index 81cc457..0e2cb72 100644 --- a/S20_env +++ b/S20_env @@ -15,3 +15,5 @@ export EDITOR=vim export LANG=fr_BE.UTF-8 +# Virtual env in prompt is already supported. +export VIRTUAL_ENV_DISABLE_PROMPT="yes" \ No newline at end of file diff --git a/S60_virtualenv b/S60_virtualenv new file mode 100644 index 0000000..6c5948b --- /dev/null +++ b/S60_virtualenv @@ -0,0 +1,15 @@ +#! /usr/bin/zsh + +# Those can be used, for instance to construct the prompt: +__ZSH_VIRTUAL_ENV_NAME="" + +virtualenv_precmd() { + if [[ -n "${VIRTUAL_ENV}" ]]; then + __ZSH_VIRTUAL_ENV_NAME="$(basename ${VIRTUAL_ENV})" + else + __ZSH_VIRTUAL_ENV_NAME="" + fi +} + + +precmd_functions+='virtualenv_precmd' diff --git a/S90_prompt b/S90_prompt index 61ebc57..8017507 100644 --- a/S90_prompt +++ b/S90_prompt @@ -32,7 +32,7 @@ setprompt() _machine="${C_BRED}%m${C_NO}" # Git status in the pwd, if applicable - if [[ -n $__ZSH_GIT_BASEDIR ]]; then + if [[ -n ${__ZSH_GIT_BASEDIR} ]]; then _basedir="${C_GREEN}%20<..<${__ZSH_GIT_BASEDIR}%<<${C_NO}" _branch="${C_MAGENTA}@${__ZSH_GIT_BRANCH}${__ZSH_GIT_ACTION}${C_NO}" _status="${__ZSH_GIT_STATUS}" @@ -42,8 +42,14 @@ setprompt() _path="${C_GREEN}%25<..<%~%<<${C_NO}" fi + # Virtualenv activated ? + if [[ -n ${__ZSH_VIRTUAL_ENV_NAME} ]]; then + _venvname="${C_BCYAN}(${__ZSH_VIRTUAL_ENV_NAME})${C_NO}" + else + _venvname="" + fi - echo ${_username}@${_machine}:${_path} + echo ${_venvname}${_username}@${_machine}:${_path} } -- 2.39.5