# Sourced by every dev-*.sh: put this directory's profile in the environment. # # Not executable, and not a command anyone runs. `. scripts/dev-profile.sh` at # the top of a script is how a worktree bound to a second stack gets that # stack's ports without anybody editing anything. # # Three properties, in order of how much they matter: # # 1. A variable already set wins. `didbot-setup env` emits # `export NAME="${NAME:-value}"`, so `DIDBOT_PDS_PORT=3100 # ./scripts/dev-pds.sh` still means 3100. A profile is a default. # 2. A machine with no configuration is unaffected. The builtin profile is # the ports these scripts already defaulted to, so sourcing this on a # machine that has never run `didbot-setup` changes nothing. # 3. It never fails the script. A fresh checkout has no setup binary built # yet, and a script that refused to start until one existed would make # the first thing a newcomer runs the thing that does not work. _didbot_setup_binary() { # The worktree's own build first: a machine-wide install belongs to # whichever checkout ran `cargo install` last, and in a worktree the local # one is the one that matches this branch. if [ -x "./target/debug/didbot-setup" ]; then echo "./target/debug/didbot-setup" elif command -v didbot-setup >/dev/null 2>&1; then command -v didbot-setup fi } _didbot_load_profile() { local binary binary="$(_didbot_setup_binary)" if [ -z "$binary" ]; then return 0 fi local exports # Failure is silence. `env` exits non-zero when this directory resolves to # a profile that does not exist, which `didbot-setup check` reports # far better than a shell script could. if exports="$("$binary" env 2>/dev/null)" && [ -n "$exports" ]; then eval "$exports" fi } _didbot_load_profile