From 307e5de920cd74dc9d27e35a65aa47f3f8103c46 Mon Sep 17 00:00:00 2001 From: David Kerkeslager Date: Mon, 19 Feb 2018 14:11:20 -0500 Subject: [PATCH] Fix the issue where bashrc always activates in subdirectories of virtual environments --- .bashrc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.bashrc b/.bashrc index a8ebce5..399963c 100644 --- 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 -- 2.20.1