Neovim Jujutsu Workspace Manager
README.md

jjwsm.nvim #

jjwsm.nvim is a small Jujutsu workspace manager for Neovim. It can switch the invoking tabpage to another workspace, create a temporary workspace in a new tabpage, rename the invoking tabpage's workspace, or forget a workspace while closing its tabpage. There is no setup() call, configuration schema, default mapping, or filesystem-deletion command.

Requirements #

Jujutsu 0.44 is the minimum because workspace roots are serialized with the template language's json() function, including its null value for roots that cannot be resolved during listing.

Installation #

With lazy.nvim:

{
  "vapourismo/jjwsm.nvim",
  dependencies = {
    {
      "folke/snacks.nvim",
      opts = { picker = {} },
    },
  },
}

The command is registered automatically when Neovim loads the plugin.

Lua API #

Each command action is also available as a public, asynchronous Lua function:

require("jjwsm").switch()
require("jjwsm").new()
require("jjwsm").rename()
require("jjwsm").delete()
require("jjwsm").delete({ no_confirm = true })

switch(), new(), and rename() take no arguments. delete() accepts an optional { no_confirm?: boolean } table; only no_confirm = true bypasses its confirmation prompt. Other option values and legacy non-table arguments do not bypass confirmation. The bypass skips only the prompt, leaving all deletion safeguards in place.

The functions report outcomes with vim.notify(), just like the corresponding :Jjwsm subcommands. They can be used directly in keymaps:

local jjwsm = require("jjwsm")

vim.keymap.set("n", "<leader>ws", jjwsm.switch, { desc = "Switch Jujutsu workspace" })
vim.keymap.set("n", "<leader>wn", jjwsm.new, { desc = "New Jujutsu workspace" })
vim.keymap.set("n", "<leader>wr", jjwsm.rename, { desc = "Rename Jujutsu workspace" })
vim.keymap.set("n", "<leader>wd", jjwsm.delete, { desc = "Delete Jujutsu workspace" })

No setup() call is needed.

Commands #

:Jjwsm switch #

Lists the repository's other live workspaces in a Snacks picker. Both workspace name and absolute root are displayed and searchable. The workspace containing the invoking tabpage's cwd is excluded.

The tabpage and its tab-local cwd are captured when the command starts. On confirmation, the selected root is checked again and :tcd is applied only to that captured tabpage, even if another tab has since become current. If the root disappeared while the picker was open, its Jujutsu record is forgotten and no cwd is changed.

:Jjwsm new #

Prompts for a workspace name with vim.ui.input(), creates that workspace, opens one blank tabpage, and sets the tabpage's cwd to the new workspace root. The prompt is Workspace name: and has no generated default, so installed UI providers can customize it. A nonblank name is preserved verbatim and becomes the Jujutsu workspace identifier. Cancelling reports an informational notice; blank names and names already registered in the repository are rejected.

The temporary path is generated independently from the prompted name. It uses this layout:

$TMPDIR/jjwsm.nvim/jjwsm-my-repo-1

Here, my-repo is the basename of the retained default workspace root. The basename is used verbatim, including spaces, case, dots, and punctuation. Allocation starts at N = 1 and uses the lowest counter whose generated path does not exist. For example, a prompted name of feature: parser work can be registered at the path above; the identifier does not affect the path.

The operating system temporary root comes from vim.uv.os_tmpdir(), so $TMPDIR above is descriptive rather than a literal environment-variable lookup. The shared parent is created as mode 0700 when absent. An existing parent must be a real directory; symlinks and non-directory paths are rejected. The final repository-specific directory must not exist before creation and is created and populated by jj workspace add itself.

If another process wins a generated-path race, allocation resumes from the next counter with the same prompted workspace name and derived repository basename. If the rescan instead shows that the prompted name was concurrently registered, creation stops. Other Jujutsu validation and creation failures are reported without opening a tab. Because the path namespace is shared, an existing candidate directory is never reused, even when it belongs to another repository or is empty. Creation is aborted before prompting or touching the temporary parent if the default workspace root and its non-empty basename cannot be determined. Cancellation and invalid input also leave the parent untouched.

:Jjwsm rename #

Renames the non-default workspace most specifically containing the invoking tabpage's cwd. The prompt is Workspace name: and defaults to the current workspace name. Cancelling reports an informational notice. Blank names and names registered to another workspace are rejected; submitting the unchanged name is an informational no-op. Other nonblank input is preserved verbatim.

The default workspace cannot be renamed because it is the repository anchor. A rename changes only Jujutsu metadata: the workspace root, directory name, and contents remain unchanged.

The invoking tabpage and cwd are captured when the action begins. Rename lists workspaces without cleaning unrelated stale records, resolves the most-specific containing root, and checks that the captured tab still exists in the same workspace after listing and again after the prompt. It then runs jj workspace rename -- <new-name> asynchronously from that workspace's root, using an argument array. Another tab becoming current does not cancel the operation.

Success is reported with both the old and new workspace names. Only the invoking tab's Tabby label is changed to <repository>[<new-name>]. If that tab disappears or changes workspaces while Jujutsu is running, the metadata rename still succeeds, but its label is left untouched and a warning is reported.

:Jjwsm delete #

After resolving an eligible workspace, prompts with vim.ui.select() to confirm deletion. “No” is listed first, and selecting it or dismissing the prompt cancels deletion with an informational notice. “Yes” closes the invoking tabpage and forgets its workspace from Jujutsu metadata. Despite its name, this command never deletes the workspace directory or any other filesystem content. It also leaves other tabpages untouched, including tabs whose cwd refers to the same workspace.

The command is unavailable for the default workspace and when only one tabpage exists. These restrictions prevent removal of Jujutsu's primary workspace record and ensure Neovim always retains a tab. The invoking tabpage and cwd are captured when the command starts, then revalidated after the asynchronous workspace lookup and again after confirmation; if that tab disappears, changes workspace, or becomes the only remaining tab, nothing is forgotten.

The captured tab is closed first with a targeted, non-forced :tabclose, so Neovim can refuse to close modified buffers. If closure is refused, the workspace remains registered. After a successful close, the plugin runs jj workspace forget; a later Jujutsu failure is reported, but the closed tab is not recreated.

Tab names #

After a new workspace, a non-default workspace switch, or a workspace rename succeeds, jjwsm.nvim asks Tabby.nvim to name the affected tab <repository>[<workspace>]. <repository> is the retained default workspace root's basename, with its original case, spaces, and punctuation, and <workspace> is the selected or prompted workspace name. For example, creating feature: parser work for /work/Repo With Spaces.v1+Draft produces:

Repo With Spaces.v1+Draft[feature: parser work]

Switching and renaming update only their invoking tabpage, even if another tabpage is current when the user responds. A successful switch to the default workspace invokes :Tabby rename_tab without a name, removing that tab's previous explicit Tabby name. Other successful activations and renames intentionally replace the previous Tabby name. Naming is best-effort: if Tabby is not installed, its command fails, or the default basename is unavailable, jjwsm.nvim warns but keeps the completed workspace operation and previous tab name. Failed or stale operations do not update a tab name.

Cleanup and safety #

Before switch or new, the plugin inspects every workspace registered in the repository associated with the invoking tabpage cwd:

  • unresolved roots are recovered transparently without rewriting workspace records: the current workspace uses jj workspace root, while other workspaces use jj workspace root --name <name>;
  • live directories are retained, regardless of which tool created them;
  • records for roots that definitively do not exist or are not directories are forgotten with jj workspace forget;
  • roots that cannot be inspected, for example because of a permission error, are retained and produce a warning;
  • if Jujutsu cannot forget stale records, the requested operation is aborted.

rename and delete intentionally perform the same unresolved-root recovery while listing workspace records without stale-record cleanup. Rename changes only the resolved live, non-default workspace's name. Delete forgets only the live, non-default workspace most specifically containing the invoking tabpage's captured cwd.

This metadata cleanup is limited to the current repository. The plugin never deletes, empties, or reuses a filesystem path. Temporary workspace directories remain until the user or operating system removes them; a later invocation will skip any path that still exists.

The :Jjwsm command is global because Neovim has no tab-local user commands. Every invocation nevertheless resolves and validates the invoking tabpage's tab-local cwd. Jujutsu processes run asynchronously with argument arrays, so workspace names and paths are never interpolated into shell commands.

Development #

Run the dependency-light mocked tests and real Jujutsu integration tests with:

make test

The integration suite expects nvim and jj on PATH. It is currently tested with Neovim 0.12.2 and Jujutsu 0.44.0.