Created
July 7, 2017 08:59
-
-
Save marzocchi/51850a0e4713c684cc926f928d1fe0d9 to your computer and use it in GitHub Desktop.
zsh hook for loading docker-machine env by containing dir
This file contains hidden or 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
devbox-register-hook() { | |
autoload add-zsh-hook | |
add-zsh-hook chpwd devbox-load-env | |
} | |
devbox-unregister-hook() { | |
autoload add-zsh-hook | |
add-zsh-hook -d chpwd devbox-load-env | |
} | |
devbox-find() { | |
devbox-unregister-hook | |
dir=$(pwd) | |
while true; | |
do | |
db=$(pwd)/devbox | |
if [ -x "$db" ] && [ -f "$db" ] ; then | |
echo $(basename $(dirname $db)) | |
break | |
fi | |
if [ $(pwd) = "/" ]; then | |
break | |
fi | |
cd .. | |
done | |
cd "$dir" | |
devbox-register-hook | |
} | |
devbox-load-env() { | |
n=$(devbox-find) | |
if [ "$n" != "" ]; then | |
echo "Loading env for $n" | |
eval $(docker-machine env "$n") | |
iterm2_set_user_var BADGE "$n" | |
fi | |
} | |
devbox-register-hook |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment