#!/bin/sh -e
#
# ta - attach to existing tmux session by name
#
# Usage: ta <session_name>
#
# Arguments:
#   session_name - Name of existing tmux session to attach to (required)
#
# Examples:
#   ta myproject   # Attach to session named "myproject"
#   ta work        # Attach to session named "work"
#
# Returns: Attaches to specified tmux session
# Behavior: Fails if session doesn't exist (use tat/tna to create if needed)

if [ "$#" -eq 0 ]; then
  printf '%s\n' "Usage: ta <session-name>" >&2
  exit 1
fi

if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
  awk 'NR == 1 { next } /^$/ { exit } { print substr($0, 3) }' "$0"
  exit 0
fi

tmux attach-session -t "$*"
