Because you are exporting in a function you need to use declare -gx
declare --help
will give you the best and most accurate reason why but it is because all function vars are technically local
. The -g
create a global exported var for a function is ignored if not in a function and the -x
is what export
is an alias for. export
is just declare -x
. You will also need to source your script files
So it will look like this
declare -gx KEY=foo
declare -gx SECRET=bar
cd () {
command cd "$@" &&
if [[ $(pwd) = '/home/me/PycharmProjects/project1' ]]; then
conda activate project1
source ~/miniconda3/etc/activate.d/env_vars.sh
elif [[ $(pwd) = '/home/me/PycharmProjects/project2' ]]; then
conda activate project2
else
source ~/miniconda3/etc/deactivate.d/env_vars.sh
fi
}
Full disclosure I'm not sure if the -x
is completely necessary but I do it in case of sourcing a script.
Also storing in secrets in ~/.bashrc
is a general no no as it leads to bad actors getting secrets. Ontop of slowing down your interactive shell loading times