Skip to content

Instantly share code, notes, and snippets.

@dhruvasagar
Last active February 5, 2020 16:24
Show Gist options
  • Save dhruvasagar/87c59acf3b53cf1911bc6e3a8055afbf to your computer and use it in GitHub Desktop.
Save dhruvasagar/87c59acf3b53cf1911bc6e3a8055afbf to your computer and use it in GitHub Desktop.
#!/bin/bash
# GistID: 87c59acf3b53cf1911bc6e3a8055afbf
_call_func () {
declare -f -F "$1" && $1
}
typeset -A _dirsh_cache
_dirsh_hook () {
[ ${_dirsh_cache["$PWD"]} ] && [ ${_dirsh_cache["$PWD"]} = 1 ] && return
if [ "$OLDPWD" != "$HOME" ] && [ -f "$OLDPWD/.zshrc" ]; then
echo "dirsh: unloading"
source "$OLDPWD/.zshrc" &>/dev/null
_call_func "_unload" &>/dev/null
unset -f _load
unset -f _unload
_dirsh_cache["$OLDPWD"]=0
fi
if [ "$PWD" != "$HOME" ] && [ -f "$PWD/.zshrc" ]; then
echo "dirsh: loading .zshrc"
source "$PWD/.zshrc" &>/dev/null
_call_func "_load" &>/dev/null
_dirsh_cache["$PWD"]=1
fi
}
typeset -ag precmd_functions;
if [[ -z ${precmd_functions[_dirsh_hook]} ]]; then
precmd_functions+=_dirsh_hook
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment