mirror of
https://github.com/Permissionless-Software-Foundation/psf-memo.git
synced 2026-09-21 16:52:01 -07:00
Creating mono-repo from psf-memo-client
This commit is contained in:
Executable
+75
@@ -0,0 +1,75 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
usage() {
|
||||
echo "Usage: close-swarm [project-root]" >&2
|
||||
echo "Stops the SwarmForge swarm for the given project (default: current directory)." >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
if [[ "${1:-}" == "-h" || "${1:-}" == "--help" ]]; then
|
||||
usage
|
||||
fi
|
||||
|
||||
SELF_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
PROJECT_ROOT="$(cd "${1:-.}" && pwd)"
|
||||
STATE_DIR="$PROJECT_ROOT/.swarmforge"
|
||||
SOCKET_FILE="$STATE_DIR/tmux-socket"
|
||||
SESSIONS_FILE="$STATE_DIR/sessions.tsv"
|
||||
WINDOW_IDS_FILE="$STATE_DIR/window-ids"
|
||||
WINDOWS_STATE_FILE="$STATE_DIR/windows.tsv"
|
||||
|
||||
if [[ ! -d "$STATE_DIR" ]]; then
|
||||
echo "No SwarmForge swarm found at $PROJECT_ROOT (missing .swarmforge/)." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ -x "$SELF_DIR/swarmforge/scripts/swarm-cleanup.sh" ]]; then
|
||||
SCRIPT_DIR="$SELF_DIR/swarmforge/scripts"
|
||||
elif [[ -x "$SELF_DIR/swarm-cleanup.sh" ]]; then
|
||||
SCRIPT_DIR="$SELF_DIR"
|
||||
elif [[ -x "$PROJECT_ROOT/swarmforge/scripts/swarm-cleanup.sh" ]]; then
|
||||
SCRIPT_DIR="$PROJECT_ROOT/swarmforge/scripts"
|
||||
else
|
||||
echo "Could not find swarm-cleanup.sh relative to $SELF_DIR or $PROJECT_ROOT." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ ! -f "$SOCKET_FILE" ]]; then
|
||||
echo "No SwarmForge swarm found at $PROJECT_ROOT (missing .swarmforge/tmux-socket)." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
TMUX_SOCKET="$(tr -d '[:space:]' < "$SOCKET_FILE")"
|
||||
if [[ -z "$TMUX_SOCKET" ]]; then
|
||||
echo "No SwarmForge swarm found at $PROJECT_ROOT (empty tmux socket)." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
sessions=()
|
||||
if [[ -f "$SESSIONS_FILE" ]]; then
|
||||
while IFS=$'\t' read -r _index _role session _rest; do
|
||||
[[ -n "${session:-}" ]] || continue
|
||||
sessions+=("$session")
|
||||
done < "$SESSIONS_FILE"
|
||||
fi
|
||||
|
||||
if (( ${#sessions[@]} == 0 )) && [[ -f "$WINDOWS_STATE_FILE" ]]; then
|
||||
while IFS=$'\t' read -r _index _window_id session _title; do
|
||||
[[ -n "${session:-}" ]] || continue
|
||||
sessions+=("$session")
|
||||
done < "$WINDOWS_STATE_FILE"
|
||||
fi
|
||||
|
||||
if (( ${#sessions[@]} == 0 )) && [[ -S "$TMUX_SOCKET" ]]; then
|
||||
while IFS= read -r session; do
|
||||
[[ -n "$session" ]] || continue
|
||||
sessions+=("$session")
|
||||
done < <(tmux -S "$TMUX_SOCKET" list-sessions -F '#{session_name}' 2>/dev/null || true)
|
||||
fi
|
||||
|
||||
if [[ -n "${SWARMFORGE_TERMINAL:-}" && -z "${SWARMFORGE_TERMINAL_BACKEND:-}" ]]; then
|
||||
export SWARMFORGE_TERMINAL_BACKEND="$SWARMFORGE_TERMINAL"
|
||||
fi
|
||||
|
||||
"$SCRIPT_DIR/swarm-cleanup.sh" "$TMUX_SOCKET" "$WINDOW_IDS_FILE" "${sessions[@]+${sessions[@]}}"
|
||||
Reference in New Issue
Block a user