| 12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- #!/usr/bin/env bash
- set -euo pipefail
- if [[ "${1:-}" == "-h" || "${1:-}" == "--help" ]]; then
- echo "Usage: td-feature-start <workspace-name> [issue-id ...]"
- echo "Starts a new td workspace and tags provided issues."
- echo "If no issue IDs are provided, it tags the focused issue when available."
- exit 0
- fi
- if [[ "${1:-}" == "" ]]; then
- echo "Usage: td-feature-start <workspace-name> [issue-id ...]" >&2
- exit 2
- fi
- workspace_name="$1"
- shift
- ws_current="$(td ws current 2>&1 || true)"
- if ! printf "%s\n" "$ws_current" | grep -q "^No active work session$"; then
- echo "An active td workspace already exists. End it before starting a new one." >&2
- echo "$ws_current" >&2
- exit 1
- fi
- declare -a issue_ids=()
- if [[ "$#" -gt 0 ]]; then
- issue_ids=("$@")
- else
- current_out="$(td current 2>&1 || true)"
- focused_id="$(printf "%s\n" "$current_out" | sed -n 's/^FOCUSED ISSUE: \(td-[a-z0-9]*\).*/\1/p' | head -n 1)"
- if [[ -n "$focused_id" ]]; then
- issue_ids=("$focused_id")
- fi
- fi
- td ws start "$workspace_name"
- if [[ "${#issue_ids[@]}" -gt 0 ]]; then
- td ws tag "${issue_ids[@]}"
- echo "Workspace '$workspace_name' started and tagged: ${issue_ids[*]}"
- else
- echo "Workspace '$workspace_name' started (no issues tagged)."
- fi
|