Skip to content

Instantly share code, notes, and snippets.

@thepigeonoftime
Created February 4, 2022 15:57
Show Gist options
  • Save thepigeonoftime/4d90d62316f3f343d3052e0cfa541171 to your computer and use it in GitHub Desktop.
Save thepigeonoftime/4d90d62316f3f343d3052e0cfa541171 to your computer and use it in GitHub Desktop.
ZSH .direnv
autoload -U add-zsh-hook
load-dir-env() {
if [[ -f .direnv && -r .direnv ]]; then
if [[ $(history | tail -n1 | awk '{print $2}') == *"cd"* ]]; then
print -P "%F{red}.direnv loaded: $(head -n1 .direnv | sed 's/#\s//')%f"
fi
source .direnv
fi
}
add-zsh-hook chpwd load-dir-env
add-zsh-hook precmd load-dir-env
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment