A helix plugin for closing all unmodified buffers
README.md

helix-buffer-close-unmodified #

A small Steel plugin for the plugin-enabled fork of Helix that adds a :buffer-close-unmodified command to close file buffers that are unmodified according to version control (git).

Behavior #

:buffer-close-unmodified (aliased as :bcu) closes a file-backed buffer only when it is both:

  • not dirty — no unsaved in-buffer changes, and
  • clean in git — the file is tracked and has no uncommitted changes.

A buffer is checked with git status --porcelain (run from the file's directory). This means a buffer you've saved but whose file still differs from what's committed — staged or unstaged — stays open. That's the key difference from a plain "unsaved changes" check: saved-but-not-committed work is preserved in your buffer list.

Left untouched (never closed):

  • buffers with unsaved changes,
  • files with uncommitted git changes,
  • untracked files,
  • files not under git, or that git can't reason about,
  • scratch buffers (no path).

Buffers are closed by passing their paths to the builtin buffer-close, which closes them in place — no view switching, so no extra split is opened.

Requires git on your PATH.

Install #

This fork loads Steel modules from ~/.local/share/steel/cogs/. Copy the cog there:

./install.sh
# or: cp buffer-close-unmodified.scm ~/.local/share/steel/cogs/buffer-close-unmodified.scm

Then load it from ~/.config/helix/init.scm:

(require "buffer-close-unmodified.scm")

Exported functions become typable commands, so this makes :buffer-close-unmodified (and its shorthand :bcu) available. Optionally bind a key (also in init.scm, using the Steel keymap API — config.toml [keys] are not applied under the Steel engine):

(keymap (global)
        (normal ("space" ("b" ("u" ":buffer-close-unmodified")))))

Restart Helix (a full restart, not :config-reload, since the require runs at startup).

Development #

buffer-close-unmodified.scm here is the source of truth. After editing, run ./install.sh to copy it into the Steel cogs directory, then restart Helix.