คำสั่งที่กำหนดเอง
กำหนดคำสั่งที่กำหนดเองและเลย์เอาต์ workspace โดยเพิ่มไฟล์ cmux.json ลงในรากโปรเจกต์หรือ ~/.config/cmux/ คำสั่งจะปรากฏในแผงคำสั่ง
ตำแหน่งไฟล์
cmux ค้นหาการตั้งค่าจากสองที่:
- ต่อโปรเจกต์:
./cmux.json— อยู่ในไดเรกทอรีโปรเจกต์ของคุณ มีความสำคัญสูงกว่า - ทั่วไป:
~/.config/cmux/cmux.json— ใช้กับทุกโปรเจกต์ เติมคำสั่งที่ยังไม่ได้กำหนดในท้องถิ่น
การเปลี่ยนแปลงจะถูกรับโดยอัตโนมัติ — ไม่จำเป็นต้องรีสตาร์ท
สคีมา
ไฟล์ cmux.json มีอาร์เรย์ commands แต่ละคำสั่งเป็นคำสั่ง shell แบบง่ายหรือนิยาม workspace แบบเต็ม:
{
"commands": [
{
"name": "Start Dev",
"keywords": ["dev", "start"],
"workspace": { ... }
},
{
"name": "Run Tests",
"command": "npm test",
"confirm": true
}
]
}คำสั่งแบบง่าย
คำสั่งแบบง่ายรันคำสั่ง shell ในเทอร์มินัลที่กำลังโฟกัสอยู่:
{
"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 ใหม่ที่มีเลย์เอาต์กำหนดเองของการแบ่ง เทอร์มินัล และแผงเบราว์เซอร์:
{
"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— ไดเรกทอรีทำงานสำหรับ workspacecolor— สีแท็บ workspacelayout— ต้นไม้เลย์เอาต์ที่กำหนดการแบ่งและแผง
พฤติกรรมการรีสตาร์ท
ควบคุมสิ่งที่เกิดขึ้นเมื่อ 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— ตัวแปรสภาพแวดล้อมในรูปแบบคู่คีย์-ค่าurl— URL ที่จะเปิด (เฉพาะเบราว์เซอร์)focus— โฟกัสที่ surface นี้หลังสร้าง
การแก้ไขไดเรกทอรีทำงาน
.หรือ ละไว้ — ไดเรกทอรีทำงานของ workspace./subdir— สัมพัทธ์กับไดเรกทอรีทำงานของ workspace~/path— ขยายไปยังไดเรกทอรีหลัก- พาธสัมบูรณ์ — ใช้ตามที่เป็น
ตัวอย่างเต็ม
{
"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
}
]
}