# vim: ft=zsh : ${AUTOENV_AUTH_FILE:=~/.autoenv_auth} : ${AUTOENV_FILE_ENTER:=.autoenv.zsh} : ${AUTOENV_FILE_LEAVE:=.autoenv_leave.zsh} : ${AUTOENV_DISABLED:=0} : ${AUTOENV_HANDLE_LEAVE:=1} _dir_authorized() { local dir="${1}" if [ -z "${dir}" ]; then return 1 fi if [ ! -d "${dir}" ]; then return 1 fi grep "^${dir}$" "${AUTOENV_AUTH_FILE}" &>/dev/null } _autoenv() { if ! _dir_authorized "${PWD}"; then return fi if [ -f "${PWD}/${AUTOENV_FILE_ENTER}" ]; then source "${PWD}/${AUTOENV_FILE_ENTER}" fi } _autoenv_leave() { if ! _dir_authorized "${OLDPWD}"; then return fi if [ -f "${OLDPWD}/${AUTOENV_FILE_LEAVE}" ]; then source "${OLDPWD}/${AUTOENV_FILE_LEAVE}" fi } alias autoenv-auth='echo "\n${PWD}" >> "${AUTOENV_AUTH_FILE}"' if [[ "${AUTOENV_DISABLED}" != 1 ]]; then autoload -U add-zsh-hook add-zsh-hook chpwd _autoenv if [[ "${AUTOENV_HANDLE_LEAVE}" == 1 ]]; then add-zsh-hook chpwd _autoenv_leave fi if [ -f "${PWD}/${AUTOENV_FILE_ENTER}" ]; then if _dir_authorized "${PWD}"; then source "${PWD}/${AUTOENV_FILE_ENTER}" fi fi fi