カスタムコマンド

プロジェクトルートまたは ~/.config/cmux/ に cmux.json ファイルを追加してカスタムコマンドとワークスペースレイアウトを定義します。コマンドはコマンドパレットに表示されます。

ファイルの場所

cmux は2か所で設定を検索します:

  • プロジェクトごと: ./cmux.jsonプロジェクトディレクトリに置かれ、優先されます
  • グローバル: ~/.config/cmux/cmux.jsonすべてのプロジェクトに適用され、ローカルで未定義のコマンドを補完します
ローカルコマンドは同名のグローバルコマンドを上書きします。

変更は自動的に反映されます — 再起動は不要です。

スキーマ

cmux.json ファイルには commands 配列が含まれます。各コマンドはシンプルなシェルコマンドまたは完全なワークスペース定義です:

cmux.json
{
  "commands": [
    {
      "name": "Start Dev",
      "keywords": ["dev", "start"],
      "workspace": { ... }
    },
    {
      "name": "Run Tests",
      "command": "npm test",
      "confirm": true
    }
  ]
}

シンプルコマンド

シンプルコマンドは現在フォーカスされているターミナルでシェルコマンドを実行します:

cmux.json
{
  "commands": [
    {
      "name": "Run Tests",
      "keywords": ["test", "check"],
      "command": "npm test",
      "confirm": true
    }
  ]
}

フィールド

  • nameコマンドパレットに表示されます(必須)
  • description任意の説明
  • keywordsコマンドパレット用の追加検索キーワード
  • commandフォーカスされたターミナルで実行するシェルコマンド
  • confirm実行前に確認ダイアログを表示する

シンプルコマンドはフォーカスされたターミナルの現在の作業ディレクトリで実行されます。プロジェクト相対パスに依存するコマンドの場合は、先頭に cd "$(git rev-parse --show-toplevel)" && を付けてリポジトリのルートから実行するか、 cd /your/path && で任意のディレクトリを指定できます。

ワークスペースコマンド

ワークスペースコマンドは、分割、ターミナル、ブラウザペインのカスタムレイアウトで新しいワークスペースを作成します:

cmux.json
{
  "commands": [
    {
      "name": "Dev Environment",
      "keywords": ["dev", "fullstack"],
      "restart": "confirm",
      "workspace": {
        "name": "Dev",
        "cwd": ".",
        "layout": {
          "direction": "horizontal",
          "split": 0.5,
          "children": [
            {
              "pane": {
                "surfaces": [
                  {
                    "type": "terminal",
                    "name": "Frontend",
                    "command": "npm run dev",
                    "focus": true
                  }
                ]
              }
            },
            {
              "pane": {
                "surfaces": [
                  {
                    "type": "terminal",
                    "name": "Backend",
                    "command": "cargo watch -x run",
                    "cwd": "./server",
                    "env": { "RUST_LOG": "debug" }
                  }
                ]
              }
            }
          ]
        }
      }
    }
  ]
}

ワークスペースフィールド

  • nameワークスペースのタブ名(デフォルトはコマンド名)
  • cwdワークスペースの作業ディレクトリ
  • colorワークスペースのタブカラー
  • layout分割とペインを定義するレイアウトツリー

再起動の動作

同名のワークスペースが既に存在する場合の動作を制御します:

  • "ignore"既存のワークスペースに切り替える(デフォルト)
  • "recreate"確認なしに閉じて再作成する
  • "confirm"再作成前にユーザーに確認する

レイアウトツリー

レイアウトツリーは、再帰的な分割ノードを使用してペインの配置を定義します:

分割ノード

スペースを2つの子に分割します:

  • direction"horizontal" または "vertical"
  • split分割位置(0.1〜0.9、デフォルト0.5)
  • children正確に2つの子ノード(分割またはペイン)

ペインノード

1つ以上のサーフェス(ペイン内のタブ)を含むリーフノード。

サーフェス定義

ペイン内の各サーフェスはターミナルまたはブラウザです:

  • type"terminal" または "browser"
  • nameカスタムタブタイトル
  • command作成時に自動実行するシェルコマンド(ターミナルのみ)
  • cwdこのサーフェスの作業ディレクトリ
  • envキーと値のペアとしての環境変数
  • url開くURL(ブラウザのみ)
  • focus作成後にこのサーフェスにフォーカスする

作業ディレクトリの解決

  • . または 省略ワークスペースの作業ディレクトリ
  • ./subdirワークスペースの作業ディレクトリからの相対パス
  • ~/pathホームディレクトリに展開
  • 絶対パスそのまま使用

完全な例

cmux.json
{
  "commands": [
    {
      "name": "Web Dev",
      "description": "Docs site with live preview",
      "keywords": ["web", "docs", "next", "frontend"],
      "restart": "confirm",
      "workspace": {
        "name": "Web Dev",
        "cwd": "./web",
        "color": "#3b82f6",
        "layout": {
          "direction": "horizontal",
          "split": 0.5,
          "children": [
            {
              "pane": {
                "surfaces": [
                  {
                    "type": "terminal",
                    "name": "Next.js",
                    "command": "npm run dev",
                    "focus": true
                  }
                ]
              }
            },
            {
              "direction": "vertical",
              "split": 0.6,
              "children": [
                {
                  "pane": {
                    "surfaces": [
                      {
                        "type": "browser",
                        "name": "Preview",
                        "url": "http://localhost:3777"
                      }
                    ]
                  }
                },
                {
                  "pane": {
                    "surfaces": [
                      {
                        "type": "terminal",
                        "name": "Shell",
                        "env": { "NODE_ENV": "development" }
                      }
                    ]
                  }
                }
              ]
            }
          ]
        }
      }
    },
    {
      "name": "Debug Log",
      "description": "Tail the debug event log from the running dev app",
      "keywords": ["log", "debug", "tail", "events"],
      "restart": "ignore",
      "workspace": {
        "name": "Debug Log",
        "layout": {
          "direction": "horizontal",
          "split": 0.5,
          "children": [
            {
              "pane": {
                "surfaces": [
                  {
                    "type": "terminal",
                    "name": "Events",
                    "command": "tail -f /tmp/cmux-debug.log",
                    "focus": true
                  }
                ]
              }
            },
            {
              "pane": {
                "surfaces": [
                  {
                    "type": "terminal",
                    "name": "Shell"
                  }
                ]
              }
            }
          ]
        }
      }
    },
    {
      "name": "Setup",
      "description": "Initialize submodules and build dependencies",
      "keywords": ["setup", "init", "install"],
      "command": "./scripts/setup.sh",
      "confirm": true
    },
    {
      "name": "Reload",
      "description": "Build and launch the debug app tagged to the current branch",
      "keywords": ["reload", "build", "run", "launch"],
      "command": "./scripts/reload.sh --tag $(git branch --show-current)"
    },
    {
      "name": "Run Unit Tests",
      "keywords": ["test", "unit"],
      "command": "./scripts/test-unit.sh",
      "confirm": true
    }
  ]
}