Skip to content
1        10        20        30        40        50        60        70        801#!/usr/bin/env bash2set -euo pipefail34script_dir="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"5repo_root="$(cd -- "$script_dir/.." && pwd)"6projects_dir="$repo_root/projects"7projects=()89for project_dir in "$projects_dir"/*; do10  if [[ -d "$project_dir" && -f "$project_dir/mise.toml" ]]; then11    projects+=("${project_dir##*/}")12  fi13done1415usage() {16  cat <<'EOF'17Usage: scripts/run-project [PROJECT]1819Select a project and run its `mise run run` task.20With no argument, show an interactive project menu.2122Options:23  -l, --list   List available projects24  -h, --help   Show this help25EOF26}2728if ((${#projects[@]} == 0)); then29  printf 'No projects with mise.toml found under %s\n' "$projects_dir" >&230  exit 131fi3233case "${1-}" in34  -h|--help)35    usage36    exit 037    ;;38  -l|--list)39    printf '%s\n' "${projects[@]}"40    exit 041    ;;42esac4344if (($# > 1)); then45  usage >&246  exit 247fi4849selected="${1-}"50if [[ -z "$selected" ]]; then51  if [[ ! -t 0 ]]; then52    printf 'Interactive selection needs a terminal; pass a project name instead.\n' >&253    exit 254  fi5556  PS3='Choose a project (Ctrl-C to cancel): '57  select choice in "${projects[@]}"; do58    if [[ -n "${choice:-}" ]]; then59      selected="$choice"60      break61    fi62    printf 'Invalid selection. Choose a number from 1 to %d.\n' "${#projects[@]}" >&263  done64fi6566selected_dir="$projects_dir/$selected"67if [[ ! -d "$selected_dir" || ! -f "$selected_dir/mise.toml" ]]; then68  printf 'Unknown project: %s\n\nAvailable projects:\n' "$selected" >&269  printf '  %s\n' "${projects[@]}" >&270  exit 271fi7273if ! command -v mise >/dev/null 2>&1; then74  printf 'mise was not found on PATH. Install mise, then retry.\n' >&275  exit 12776fi7778cd -- "$selected_dir"79exec mise run run