#工作區群組

工作區群組讓你能將工作區巢狀歸入側邊欄中可折疊的具名區段。每個群組都有一個隱含的錨點工作區、一個可自訂用來在群組內建立新工作區的 + 按鈕,以及用於重新命名、釘選、解除群組和編輯其設定的右鍵動作。

#概念

#錨點工作區

每個群組都恰好由一個稱為錨點的工作區擁有。側邊欄中的群組標頭即是錨點的呈現方式——它沒有獨立的列。點按標頭名稱區域會聚焦於錨點的面板;點按箭號則切換折疊狀態。

A group's anchor is always a brand new workspace at creation time; grouping a selection or creating a group never promotes one of your existing workspaces into the anchor. (Closing an anchor later does promote the group's first remaining member, see below.) The anchor's working directory is inherited from the first selected workspace when grouping a selection, or from the active workspace when creating via the CLI without --cwd.

Closing the anchor workspace closes only that workspace and promotes the group's first remaining member (the earliest one still in the group's order) to be the new anchor, so the group and its other members stay intact (the promoted member then shows the group name as the header). When the anchor is the group's only workspace, the group is removed. To flatten a group into ungrouped workspaces use Ungroup; to close every workspace in a group use Delete Group.

#群組識別

群組具有名稱、圖示(一個 SF Symbol,預設為 folder.fill),以及一個選用的自訂顏色。這些都獨立於錨點工作區本身的自訂設定。錨點的顏色和圖示在建立時會以群組為種子值,但之後可以各自不同。

#釘選

群組可以獨立於個別工作區的釘選而釘選。已釘選的頂層列,無論是個別工作區還是群組,都會位於未釘選列的上方。在每個層級之內,群組和工作區會保留你拖曳放入的順序。

側邊欄由上而下排列頂層列:

  1. 已釘選的頂層列(工作區與群組)。
  2. 未釘選的頂層列(工作區與群組)。

#建立群組

群組可從鍵盤快捷鍵或側邊欄內容選單建立。空白群組會插入新的錨點工作區作為群組標題。以選取項目建立的群組會把該錨點插入選取項目上方,並將選取的工作區移入群組。群組建立後,你可以從群組標題管理它並加入工作區(請見下方的管理群組)。

#從鍵盤快捷鍵

按 ⌃⌘G 可建立新的空白工作區群組。在側邊欄選取兩個以上工作區,然後按 ⌘⇧G 將選取項目分組。兩種方式都會建立新的錨點工作區,並自動命名為 Group 1、Group 2 等等。可隨時從標題內容選單重新命名。

⌘⇧G 與 React Grab 的預設快捷鍵相衝突。群組處理常式只有在側邊欄明確多選至少兩個工作區時才會消耗此和弦,因此在單選以及瀏覽器或終端機情境中,React Grab 仍會觸發。如果你不希望兩者共用同一個按鍵,可以在「設定 → 鍵盤」中重新繫結。

單一分頁群組無法透過快捷鍵建立。請改用工作區右鍵選單中的 New Group from Workspace 項目來建立。

#透過工作區情境選單

在側邊欄中的任何工作區按右鍵,選擇新增空白工作區群組、從工作區新增群組,或在選取多個工作區時選擇從選取項目新增群組。側邊欄清單下方的空白區域也提供新增空白工作區群組。這些路徑使用與快捷鍵相同的自動命名行為。

#管理群組

群組建立後,可以透過其標題的右鍵選單以及標題上的 + 按鈕來管理群組並向其中新增工作區。這兩者都不會建立新群組。

#透過群組標頭情境選單

對現有的群組標題列按右鍵,可使用 Rename Group…、Pin Group / Unpin Group、Edit Group Config…(會開啟 ~/.config/cmux/cmux.json)、Open Workspace Groups Docs、Ungroup Workspaces 以及 Delete Group。Ungroup Workspaces 會保留工作區,僅移除群組容器。Delete Group 會關閉群組標題工作區以及群組內的所有工作區;如果群組包含子工作區,會先提示確認。

#透過群組標頭上的 + 按鈕

將滑鼠移到群組標題列上,即可顯示尾端的 + 按鈕。點按它即可在該群組中、於錨點工作目錄下建立新的工作區。對它按右鍵則可使用 New Workspace in Group、Edit Group Config… 以及 Open Workspace Groups Docs。

當目前作用中的工作區是某個群組的錨點或成員時,按下 ⌘N 也會在該群組內建立新工作區。預設放置方式為 After current:從一般的群組成員出發時,新工作區會落在作用中成員的正後方;從錨點或標頭出發時,則會落在群組的頂端。

#CLI

所有群組操作皆可透過 cmux workspace-group 子命令編寫指令稿。帶連字號的形式將率先推出;一旦更廣泛的 cmux workspace 命令命名空間上線,cmux workspace group 將成為標準形式,而帶連字號的形式將永久保留作為別名。

#子指令

cmux workspace-group list [--json]
cmux workspace-group create --name "manaflow" [--cwd ~/projects/manaflow] [--from <id>,<id>]
cmux workspace-group ungroup <group-id>
cmux workspace-group delete  <group-id>
cmux workspace-group delete  <group-id> --close-workspaces
cmux workspace-group rename <group-id> --name "new name"
cmux workspace-group collapse <group-id>
cmux workspace-group expand <group-id>
cmux workspace-group pin <group-id>
cmux workspace-group unpin <group-id>
cmux workspace-group add --group <group-id> --workspace <workspace-id>
cmux workspace-group remove --workspace <workspace-id>
cmux workspace-group set-anchor --group <group-id> --workspace <workspace-id>
cmux workspace-group new-workspace <group-id> [--placement afterCurrent|top|end]
cmux workspace-group set-color <group-id> --hex "#7A4FD8"
cmux workspace-group set-icon  <group-id> --symbol ladybug.fill
cmux workspace-group move <group-id> (--to-index <n> | --before <group-id> | --after <group-id>)
cmux workspace-group focus <group-id>

create 會回傳一個群組控制代碼(預設為 workspace_group:N)。傳入 --json 可取得完整的結構化負載。

傳給 set-color 或 set-icon 一個空值即可清除群組的顏色或圖示。delete 是不可逆的:它會關閉每個成員工作區。

#範例

將目前選取的工作區以某個名稱進行群組化:

cmux workspace-group create --name manaflow --from workspace:1,workspace:2

在現有群組內建立一個新工作區,例如連接到某個 worktree 指令稿:

cmux workspace-group new-workspace workspace_group:1

列出聚焦視窗中的群組:

cmux workspace-group list

#設定

每個群組的設定位於 ~/.config/cmux/cmux.json 中的 workspaceGroups 鍵之下,並以錨點工作區的工作目錄作為鍵。請參閱設定參考,以了解所支援的鍵,包括全域新工作區放置位置,以及各目錄的色彩、圖示、放置位置和右鍵選單動作。

workspaceGroups 設定參考

#持久化

群組名稱、錨點、釘選狀態、折疊狀態、顏色與圖示都會與你的工作區一併儲存,並在重新啟動後還原。群組成員資格則儲存在每個工作區上。