#!/usr/bin/env bash
# Resolve the real directory this script lives in, even through symlinks.
# macOS's built-in readlink has no -f flag (that's a GNU coreutils
# extension), so we can't rely on `readlink -f` the way a Linux script
# would — this loop is the standard portable workaround.
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do
  DIR="$(cd -P "$(dirname "$SOURCE")" >/dev/null 2>&1 && pwd)"
  SOURCE="$(readlink "$SOURCE")"
  [[ "$SOURCE" != /* ]] && SOURCE="$DIR/$SOURCE"
done
HERE="$(cd -P "$(dirname "$SOURCE")" >/dev/null 2>&1 && pwd)"

export PYTHONHOME="$HERE"
export DYLD_LIBRARY_PATH="$HERE/lib${DYLD_LIBRARY_PATH:+:$DYLD_LIBRARY_PATH}"
export TERMINFO="$HERE/share/terminfo"
unset PYTHONPATH
export PYTHONDONTWRITEBYTECODE=1
exec "$HERE/bin/todtler" "$@"
