คำสั่งที่กำหนดเอง

กำหนดคำสั่งที่กำหนดเองและเลย์เอาต์ workspace โดยเพิ่มไฟล์ cmux.json ลงในรากโปรเจกต์หรือ ~/.config/cmux/ คำสั่งจะปรากฏในแผงคำสั่ง

ตำแหน่งไฟล์

cmux ค้นหาการตั้งค่าจากสองที่:

  • ต่อโปรเจกต์: ./cmux.jsonอยู่ในไดเรกทอรีโปรเจกต์ของคุณ มีความสำคัญสูงกว่า
  • ทั่วไป: ~/.config/cmux/cmux.jsonใช้กับทุกโปรเจกต์ เติมคำสั่งที่ยังไม่ได้กำหนดในท้องถิ่น
คำสั่งท้องถิ่นจะแทนที่คำสั่งทั่วไปที่มีชื่อเดียวกัน

การเปลี่ยนแปลงจะถูกรับโดยอัตโนมัติ — ไม่จำเป็นต้องรีสตาร์ท

สคีมา

ไฟล์ cmux.json มีอาร์เรย์ commands แต่ละคำสั่งเป็นคำสั่ง shell แบบง่ายหรือนิยาม workspace แบบเต็ม:

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

คำสั่งแบบง่าย

คำสั่งแบบง่ายรันคำสั่ง shell ในเทอร์มินัลที่กำลังโฟกัสอยู่:

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

ฟิลด์

  • nameแสดงในแผงคำสั่ง (จำเป็น)
  • descriptionคำอธิบายเพิ่มเติม (ไม่บังคับ)
  • keywordsคำค้นหาเพิ่มเติมสำหรับแผงคำสั่ง
  • commandคำสั่ง shell ที่จะรันในเทอร์มินัลที่โฟกัส
  • confirmแสดงกล่องโต้ตอบยืนยันก่อนรัน

คำสั่งแบบง่ายจะรันในไดเรกทอรีการทำงานปัจจุบันของเทอร์มินัลที่โฟกัสอยู่ หากคำสั่งของคุณใช้พาธสัมพัทธ์กับโปรเจกต์ ให้เพิ่มนำหน้าด้วย cd "$(git rev-parse --show-toplevel)" && เพื่อรันจากรูทของ repo หรือ cd /your/path && สำหรับไดเรกทอรีที่ต้องการ

คำสั่ง workspace

คำสั่ง workspace สร้าง workspace ใหม่ที่มีเลย์เอาต์กำหนดเองของการแบ่ง เทอร์มินัล และแผงเบราว์เซอร์:

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" }
                  }
                ]
              }
            }
          ]
        }
      }
    }
  ]
}

ฟิลด์ workspace

  • nameชื่อแท็บ workspace (ค่าเริ่มต้นคือชื่อคำสั่ง)
  • cwdไดเรกทอรีทำงานสำหรับ workspace
  • colorสีแท็บ workspace
  • layoutต้นไม้เลย์เอาต์ที่กำหนดการแบ่งและแผง

พฤติกรรมการรีสตาร์ท

ควบคุมสิ่งที่เกิดขึ้นเมื่อ workspace ที่มีชื่อเดียวกันมีอยู่แล้ว:

  • "ignore"สลับไปยัง workspace ที่มีอยู่ (ค่าเริ่มต้น)
  • "recreate"ปิดและสร้างใหม่โดยไม่ถาม
  • "confirm"ถามผู้ใช้ก่อนสร้างใหม่

ต้นไม้เลย์เอาต์

ต้นไม้เลย์เอาต์กำหนดวิธีจัดเรียงแผงโดยใช้โหนดการแบ่งแบบวนซ้ำ:

โหนดการแบ่ง

แบ่งพื้นที่ออกเป็นสองส่วน:

  • direction"horizontal" หรือ "vertical"
  • splitตำแหน่งตัวแบ่งตั้งแต่ 0.1 ถึง 0.9 (ค่าเริ่มต้น 0.5)
  • childrenโหนดลูกสองโหนดพอดี (การแบ่งหรือแผง)

โหนดแผง

โหนดใบที่มี surface หนึ่งอันหรือมากกว่า (แท็บภายในแผง)

นิยาม surface

แต่ละ surface ในแผงสามารถเป็นเทอร์มินัลหรือเบราว์เซอร์:

  • type"terminal" หรือ "browser"
  • nameชื่อแท็บที่กำหนดเอง
  • commandคำสั่ง shell ที่รันอัตโนมัติเมื่อสร้าง (เฉพาะเทอร์มินัล)
  • cwdไดเรกทอรีทำงานสำหรับ surface นี้
  • envตัวแปรสภาพแวดล้อมในรูปแบบคู่คีย์-ค่า
  • urlURL ที่จะเปิด (เฉพาะเบราว์เซอร์)
  • focusโฟกัสที่ surface นี้หลังสร้าง

การแก้ไขไดเรกทอรีทำงาน

  • . หรือ ละไว้ไดเรกทอรีทำงานของ workspace
  • ./subdirสัมพัทธ์กับไดเรกทอรีทำงานของ workspace
  • ~/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
    }
  ]
}