Files
bash-it/plugins/available/z_autoenv.plugin.bash
John D Pell dee55a03cc drop dirname in favor of native Bash strings (1 of 2)
Convert `var=${dirname $filename)` to `var="${filename%/*}` in cases where there is no ambiguity.

Make sure that the path in `$BASH_IT` is absolute because this path gets embedded in the template `.bash_profile` file if selected by the user.
2021-09-16 16:59:02 -07:00

46 lines
696 B
Bash

cite about-plugin
about-plugin 'source into environment when cding to directories'
if [[ -n "${ZSH_VERSION}" ]]
then __array_offset=0
else __array_offset=1
fi
autoenv_init()
{
typeset target home _file
typeset -a _files
target=$1
home="${HOME%/*}"
_files=( $(
while [[ "$PWD" != "/" && "$PWD" != "$home" ]]
do
_file="$PWD/.env"
if [[ -e "${_file}" ]]
then echo "${_file}"
fi
builtin cd ..
done
) )
_file=${#_files[@]}
while (( _file > 0 ))
do
source "${_files[_file-__array_offset]}"
: $(( _file -= 1 ))
done
}
cd()
{
if builtin cd "$@"
then
autoenv_init
return 0
else
echo "else?"
return $?
fi
}