#!/bin/bash
# Wrapper for bd that resolves BEADS_DIR by walking up from CWD when unset.
# Placed in $OLLIE/x/ so it shadows the real bd on PATH for tool subprocesses.
if [ -z "$BEADS_DIR" ]; then
    dir="$PWD"
    while [ "$dir" != "/" ] && [ -e "$dir/.git" ]; do
        if [ -d "$dir/.beads" ]; then
            export BEADS_DIR="$dir/.beads"
            break
        fi
        dir="$(dirname "$dir")"
    done
fi
exec "$HOME/.local/bin/bd" "$@"
