diff --git a/plugins/available/z_autoenv.plugins.bash b/plugins/available/z_autoenv.plugins.bash new file mode 100644 index 00000000..a145a390 --- /dev/null +++ b/plugins/available/z_autoenv.plugins.bash @@ -0,0 +1,46 @@ +#!/usr/bin/env bash +echo "hi from autoenv" +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="$(dirname $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 + echo "running autoenv_init" + autoenv_init + return 0 + else + echo "else?" + return $? + fi +} +echo "cd has been replaced"