Created
March 26, 2026 03:51
-
-
Save taiyoh/281f9143286badb43b6c109516df9a27 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| set -euo pipefail | |
| # Usage: | |
| # cmux_setup.sh [--name <workspace_name>] | |
| # cmux_setup.sh --new-workspace [--name <workspace_name>] | |
| # cmux_setup.sh --llm codex --name mydev | |
| # | |
| # Env overrides: | |
| # LLM_CMD=codex cmux_setup.sh | |
| # FILES_CMD='yazi .' LLM_CMD='claude' GIT_CMD='lazygit' cmux_setup.sh | |
| WORKSPACE_NAME="" | |
| FILES_CMD="${FILES_CMD:-yazi .}" | |
| LLM_CMD="${LLM_CMD:-claude}" | |
| GIT_CMD="${GIT_CMD:-lazygit}" | |
| NEW_WORKSPACE=false | |
| while [[ $# -gt 0 ]]; do | |
| case "$1" in | |
| --new-workspace) | |
| NEW_WORKSPACE=true | |
| ;; | |
| --name) | |
| if [[ -z "${2:-}" || "${2:0:1}" == "-" ]]; then | |
| echo "エラー: --name にはワークスペース名を指定してください。" | |
| exit 1 | |
| fi | |
| WORKSPACE_NAME="$2" | |
| shift | |
| ;; | |
| --llm) | |
| if [[ -z "${2:-}" || "${2:0:1}" == "-" ]]; then | |
| echo "エラー: --llm にはコマンド名を指定してください。" | |
| exit 1 | |
| fi | |
| LLM_CMD="$2" | |
| shift | |
| ;; | |
| *) | |
| echo "不明な引数: $1" | |
| echo "Usage: cmux_setup.sh [--new-workspace] [--name <workspace_name>] [--llm <command>]" | |
| exit 1 | |
| ;; | |
| esac | |
| shift | |
| done | |
| # Parse surface ref (e.g. "surface:9") from cmux output like "OK surface:9 workspace:4" | |
| parse_surface() { | |
| echo "$1" | grep -o 'surface:[^ ]*' | |
| } | |
| # Convert surface:N to pane:N | |
| surface_to_pane() { | |
| echo "$1" | sed 's/^surface:/pane:/' | |
| } | |
| setup_layout() { | |
| local ws_id="$1" | |
| local skip_files="${2:-false}" | |
| # Get the first pane's surface in the workspace (files pane) | |
| local files_pane files_surface | |
| files_pane="$(cmux list-panes --workspace "$ws_id" | head -1 | grep -o 'pane:[^ ]*')" | |
| files_surface="$(cmux list-pane-surfaces --workspace "$ws_id" --pane "$files_pane" | head -1 | grep -o 'surface:[^ ]*')" | |
| # Split right to create llm pane | |
| local llm_surface | |
| llm_surface="$(parse_surface "$(cmux new-split right --workspace "$ws_id")")" | |
| # Split llm pane down to create git pane | |
| local git_surface | |
| git_surface="$(parse_surface "$(cmux new-split down --surface "$llm_surface" --workspace "$ws_id")")" | |
| # Resize panes to match tmux layout | |
| local llm_pane | |
| llm_pane="$(surface_to_pane "$llm_surface")" | |
| cmux resize-pane --pane "$files_pane" -R --amount 10 2>/dev/null || true | |
| cmux resize-pane --pane "$llm_pane" -D --amount 5 2>/dev/null || true | |
| # Wait for shells to initialize | |
| sleep 0.5 | |
| # Launch tools in each surface | |
| if [[ "$skip_files" != "true" ]]; then | |
| cmux send --workspace "$ws_id" --surface "$files_surface" -- "$FILES_CMD\n" | |
| fi | |
| cmux send --workspace "$ws_id" --surface "$llm_surface" -- "$LLM_CMD\n" | |
| cmux send --workspace "$ws_id" --surface "$git_surface" -- "$GIT_CMD\n" | |
| # Focus the llm pane | |
| cmux focus-pane --workspace "$ws_id" "$llm_surface" 2>/dev/null || true | |
| } | |
| if [[ "$NEW_WORKSPACE" == "true" ]]; then | |
| # Create a new workspace | |
| ws_output="$(cmux new-workspace)" | |
| # new-workspace returns "OK <uuid>" — extract the UUID | |
| ws_id="$(echo "$ws_output" | awk '{print $2}')" | |
| if [[ -z "$ws_id" ]]; then | |
| echo "エラー: ワークスペースの作成に失敗しました。" | |
| exit 1 | |
| fi | |
| # Rename workspace if a name was given | |
| if [[ -n "$WORKSPACE_NAME" ]]; then | |
| cmux rename-workspace --workspace "$ws_id" "$WORKSPACE_NAME" | |
| fi | |
| setup_layout "$ws_id" | |
| echo "ワークスペース '${WORKSPACE_NAME:-$ws_id}' をセットアップしました。" | |
| exit 0 | |
| fi | |
| # Use the current workspace | |
| if [[ -z "${CMUX_WORKSPACE_ID:-}" ]]; then | |
| echo "cmux内で実行してください。" | |
| echo "新規ワークスペースで行う場合: cmux_setup.sh --new-workspace [--name <workspace_name>]" | |
| exit 1 | |
| fi | |
| if [[ -n "$WORKSPACE_NAME" ]]; then | |
| cmux rename-workspace --workspace "$CMUX_WORKSPACE_ID" "$WORKSPACE_NAME" | |
| fi | |
| setup_layout "$CMUX_WORKSPACE_ID" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment