]> git.alrj.org Git - zsh.d.git/commitdiff
Add support for virtualenv name in prompt.
authorAmand Tihon <amand.tihon@iba-group.com>
Wed, 7 Dec 2016 10:31:14 +0000 (11:31 +0100)
committerAmand Tihon <amand.tihon@iba-group.com>
Wed, 7 Dec 2016 10:31:14 +0000 (11:31 +0100)
S20_env
S60_virtualenv [new file with mode: 0644]
S90_prompt

diff --git a/S20_env b/S20_env
index 81cc4570d943dd42bfd6083016c6310baa3dafaa..0e2cb7218996966d8af2dbdf38f9e80cec710ad5 100644 (file)
--- 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 (file)
index 0000000..6c5948b
--- /dev/null
@@ -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'
index 61ebc570e1a7c521e6cb822faf87edb0889c3d7f..8017507d5331239836200f2b2fac3a29e94bced1 100644 (file)
@@ -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}
 }