Last active
February 5, 2020 16:24
-
-
Save dhruvasagar/87c59acf3b53cf1911bc6e3a8055afbf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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