diff --git a/home/user/.config/zsh/autoenv b/home/user/.config/zsh/autoenv new file mode 100644 index 0000000..b3d52c0 --- /dev/null +++ b/home/user/.config/zsh/autoenv @@ -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 \ No newline at end of file diff --git a/home/user/.config/zsh/other b/home/user/.config/zsh/other index 7d96a1a..9348d43 100644 --- a/home/user/.config/zsh/other +++ b/home/user/.config/zsh/other @@ -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 \ No newline at end of file diff --git a/home/user/.config/zsh/sourcer b/home/user/.config/zsh/sourcer index fbdb076..2aca767 100644 --- a/home/user/.config/zsh/sourcer +++ b/home/user/.config/zsh/sourcer @@ -29,6 +29,8 @@ _so "${ZDOTDIR}/hosts/${HOST}" source "${ZDOTDIR}/plugin" +source "${ZDOTDIR}/autoenv" + source "${ZDOTDIR}/mappings" source "${ZDOTDIR}/accept_line"