Skip to content

Instantly share code, notes, and snippets.

@costa
Last active April 6, 2016 11:32
Show Gist options
  • Save costa/985dc820218fb78ea8554eb150f21087 to your computer and use it in GitHub Desktop.
Save costa/985dc820218fb78ea8554eb150f21087 to your computer and use it in GitHub Desktop.
.dockerrc-enabling bash init
# NOTE source this file from $HOME/.bashrc
# NOTE and have a .dockerrc — e.g. containing "eval $(docker-machine env default)" — in your project directory
_before_dmm_docker() { command docker "$@"; }
OLD_DOCKER_FUNC="`declare -f docker`"
if [ -n "$OLD_DOCKER_FUNC" ]
then eval "_before_dmm_$OLD_DOCKER_FUNC"
fi
docker() {
local OLD_IFS="$IFS"
IFS=$'\n'
for dir in `while echo "$PWD" && [ "$PWD" != '/' ] && cd ..; do :; done`
do [ -n "$OLD_IFS" ] && IFS="$OLD_IFS" && OLD_IFS= # NOTE will probably be executed once at least
local NEW_DOCKER_RC="$dir"/.dockerrc
if [ -s "$NEW_DOCKER_RC" ]
then break
else NEW_DOCKER_RC=
fi
done
if [ -z "$NEW_DOCKER_RC" ]
then >&2 echo "No .dockerrc found. Trying to run docker anyway. (\$DOCKER_RC=$DOCKER_RC \$DOCKER_HOST=$DOCKER_HOST)"
elif [ "$NEW_DOCKER_RC" != "$DOCKER_RC" ]
then source "$NEW_DOCKER_RC" && export DOCKER_RC="$NEW_DOCKER_RC"
fi && _before_dmm_docker "$@"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment