#!/bin/sh -e
#
# itry - a portable script for launching ipython with uvx packages
#
# ---
# source: https://til.simonwillison.net/python/itry

# show help if requested
[ "$1" = "--help" ] && {
  echo "Usage: itry [packages...]"
  echo "Example: itry llm sqlite-utils datasette"
  exit 0
}

# initialize empty string for packages
PACKAGES=""

# process all arguments, adding --with before each
for arg in "$@"; do
  PACKAGES="${PACKAGES} --with ${arg}"
done

# remove leading space if present
PACKAGES="${PACKAGES# }"

# execute uvx command with Python 3.13
exec uvx "${PACKAGES}" --python 3.13 ipython
