Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions plugins/available/z_autoenv.plugin.bash
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,36 @@ else
__array_offset=1
fi

function autoenv_init {
typeset home _file
autoenv_init() {
typeset home _file # target
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 .. || return
done
))
while [[ "$PWD" != "/" && "$PWD" != "$home" ]]; do
_file="$PWD/.env"
if [[ -e "${_file}" ]]; then
_files+=("${_file}")
fi
builtin cd .. || true
done

_file=${#_files[@]}
while ((_file > 0)); do
# shellcheck disable=SC1090
#shellcheck disable=SC1090
source "${_files[_file - __array_offset]}"
: $((_file -= 1))
done
}

cd() {
local return_code
if builtin cd "$@"; then
autoenv_init
return 0
else
return_code=$?
echo "else?"
return $?
return "$return_code"
fi
}
Loading