zsh autoenv refactor

This commit is contained in:
thek4n 2024-12-16 12:56:14 +03:00
parent 46faf1536b
commit 76568fa286
3 changed files with 44 additions and 40 deletions

View File

@ -0,0 +1,42 @@
# vim: ft=zsh
_autoenv() {
if [ -z "${PWD}" ]; then
return
fi
if ! grep "${PWD}" ~/.autoenv_authorized_dirs &>/dev/null; then
return
fi
if [ -f .env ]; then
source ./.env
fi
}
_autoenv_leave() {
if [ -z "${OLDPWD}" ]; then
return
fi
if ! grep "${OLDPWD}" ~/.autoenv_authorized_dirs &>/dev/null; then
return
fi
if [ -f "${OLDPWD}/.env.leave" ]; then
source "${OLDPWD}/.env.leave"
fi
}
autoload -U add-zsh-hook
add-zsh-hook chpwd _autoenv
add-zsh-hook chpwd _autoenv_leave
if [ -f .env ]; then
if grep "${PWD}" ~/.autoenv_authorized_dirs &>/dev/null; then
. ./.env
fi
fi

View File

@ -16,44 +16,4 @@ if [ -x /usr/bin/dircolors ]; then
# Take advantage of $LS_COLORS for completion as well
zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}"
zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31'
fi
_autoenv() {
if [ -z "${PWD}" ]; then
return
fi
if ! grep "${PWD}" ~/.autoenv_authorized_dirs &>/dev/null; then
return
fi
if [ -f .env ]; then
. ./.env
fi
}
_autoenv_leave() {
if [ -z "${OLDPWD}" ]; then
return
fi
if ! grep "${OLDPWD}" ~/.autoenv_authorized_dirs &>/dev/null; then
return
fi
if [ -f "${OLDPWD}/.env.leave" ]; then
. "${OLDPWD}/.env.leave"
fi
}
autoload -U add-zsh-hook
add-zsh-hook chpwd _autoenv
add-zsh-hook chpwd _autoenv_leave
if [ -f .env ]; then
. ./.env
fi

View File

@ -29,6 +29,8 @@ _so "${ZDOTDIR}/hosts/${HOST}"
source "${ZDOTDIR}/plugin"
source "${ZDOTDIR}/autoenv"
source "${ZDOTDIR}/mappings"
source "${ZDOTDIR}/accept_line"