Fix the issue where bashrc always activates in subdirectories of virtual environments
authorDavid Kerkeslager <kerkeslager@gmail.com>
Mon, 19 Feb 2018 19:11:20 +0000 (14:11 -0500)
committerDavid Kerkeslager <kerkeslager@gmail.com>
Mon, 19 Feb 2018 19:11:38 +0000 (14:11 -0500)
.bashrc

diff --git a/.bashrc b/.bashrc
index a8ebce5..399963c 100644 (file)
--- a/.bashrc
+++ b/.bashrc
@@ -95,12 +95,16 @@ get_env() {
     fi
 }
 
+get_absolute_path() {
+  python3 -c "import os; print(os.path.realpath('$1'))"
+}
+
 on_prompt() {
     # Load a virtualenv environment if it exists in a file named .env
     env_folder=$(get_env $(pwd))
 
     if [ -d "$env_folder" ] ; then
-        if [[ $VIRTUAL_ENV != $env_folder ]] ; then
+      if [[ $VIRTUAL_ENV != $(get_absolute_path $env_folder) ]] ; then
             echo "Activating env '$env_folder'"
             source "$env_folder/bin/activate"
         fi