td-feature-start 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. if [[ "${1:-}" == "-h" || "${1:-}" == "--help" ]]; then
  4. echo "Usage: td-feature-start <workspace-name> [issue-id ...]"
  5. echo "Starts a new td workspace and tags provided issues."
  6. echo "If no issue IDs are provided, it tags the focused issue when available."
  7. exit 0
  8. fi
  9. if [[ "${1:-}" == "" ]]; then
  10. echo "Usage: td-feature-start <workspace-name> [issue-id ...]" >&2
  11. exit 2
  12. fi
  13. workspace_name="$1"
  14. shift
  15. ws_current="$(td ws current 2>&1 || true)"
  16. if ! printf "%s\n" "$ws_current" | grep -q "^No active work session$"; then
  17. echo "An active td workspace already exists. End it before starting a new one." >&2
  18. echo "$ws_current" >&2
  19. exit 1
  20. fi
  21. declare -a issue_ids=()
  22. if [[ "$#" -gt 0 ]]; then
  23. issue_ids=("$@")
  24. else
  25. current_out="$(td current 2>&1 || true)"
  26. focused_id="$(printf "%s\n" "$current_out" | sed -n 's/^FOCUSED ISSUE: \(td-[a-z0-9]*\).*/\1/p' | head -n 1)"
  27. if [[ -n "$focused_id" ]]; then
  28. issue_ids=("$focused_id")
  29. fi
  30. fi
  31. td ws start "$workspace_name"
  32. if [[ "${#issue_ids[@]}" -gt 0 ]]; then
  33. td ws tag "${issue_ids[@]}"
  34. echo "Workspace '$workspace_name' started and tagged: ${issue_ids[*]}"
  35. else
  36. echo "Workspace '$workspace_name' started (no issues tagged)."
  37. fi