From: David Kerkeslager Date: Mon, 19 Feb 2018 19:11:20 +0000 (-0500) Subject: Fix the issue where bashrc always activates in subdirectories of virtual environments X-Git-Url: https://code.kerkeslager.com/?p=dotfiles;a=commitdiff_plain;h=307e5de920cd74dc9d27e35a65aa47f3f8103c46 Fix the issue where bashrc always activates in subdirectories of virtual environments --- 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