#!/usr/bin/env bash
# tbn — "thread by name". Short, directly-invokable wrapper:  tbn <pattern>
# Cross-site case-insensitive substring search on thread name (v1 `tbn`).
# Maps to: nc-find.sh --name <pattern> [extra flags pass through].
#
#   tbn adt                 # every thread whose name contains 'adt', all sites
#   tbn IB_ADT --format tsv # pass-through flags go straight to nc-find
set -o pipefail
_self="${BASH_SOURCE[0]}"; [ -L "$_self" ] && _self="$(readlink "$_self")"
. "$(cd "$(dirname "$_self")" && pwd)/_nc_common.sh"

if [ "${1:-}" = "-h" ] || [ "${1:-}" = "--help" ]; then
  awk 'NR==1{next} /^#/{sub(/^# ?/,""); print; next} {exit}' "${BASH_SOURCE[0]}"
  exit 0
fi
[ $# -ge 1 ] || { echo "tbn: usage: tbn <name-pattern> [--format tsv|table|jsonl]" >&2; exit 2; }

lib="$(_nc_resolve_lib)" || { echo "tbn: lib/ toolkit not found (set LARRY_LIB_DIR or LARRY_HOME)" >&2; exit 1; }
pat="$1"; shift
exec bash "$lib/nc-find.sh" --name "$pat" "$@"
