From 856716e6dc46c72367ff577f4fce8bb1390ed0ea Mon Sep 17 00:00:00 2001 From: Barrett Ruth <62671086+barrettruth@users.noreply.github.com> Date: Sat, 21 Feb 2026 22:38:38 -0500 Subject: [PATCH] feat: support vim.g.oil configuration + remove release-please (#17) * feat: support vim.g.oil declarative configuration Problem: oil.nvim requires an imperative require("oil").setup(opts) call to initialize. The Neovim ecosystem is moving toward vim.g.plugin as a declarative config source that works without explicit setup calls. Solution: fall back to vim.g.oil in config.setup() when no opts are passed, and add plugin/oil.lua to auto-initialize when vim.g.oil is set. Explicit setup(opts) calls still take precedence. Update docs and add tests for the new resolution order. Closes: barrettruth/oil.nvim#1 * build: remove release-please pipeline Problem: the release-please action creates automated releases that are not needed for this fork's workflow. Solution: remove the release job from tests.yml and the release-please branch exclusion from the review request workflow. * fix(doc): improve readme phrasing * doc: minor phrasing "improvements" * ci: add luarocks release on tag push Problem: there is no automated way to publish oil.nvim to luarocks when a new version is tagged. Solution: add a luarocks workflow that triggers on v* tag pushes, runs the test suite via workflow_call, then publishes via luarocks-tag-release. Add workflow_call trigger to tests.yml so it can be reused. --- .../workflows/automation_request_review.yml | 2 - .github/workflows/luarocks.yaml | 21 ++++++ .github/workflows/tests.yml | 25 +------ README.md | 70 +++++++++++-------- doc/oil.txt | 21 ++++++ lua/oil/config.lua | 2 +- plugin/oil.lua | 3 + tests/config_spec.lua | 27 +++++++ 8 files changed, 116 insertions(+), 55 deletions(-) create mode 100644 .github/workflows/luarocks.yaml create mode 100644 plugin/oil.lua create mode 100644 tests/config_spec.lua diff --git a/.github/workflows/automation_request_review.yml b/.github/workflows/automation_request_review.yml index 411ac60..bfc3230 100644 --- a/.github/workflows/automation_request_review.yml +++ b/.github/workflows/automation_request_review.yml @@ -4,8 +4,6 @@ permissions: on: pull_request_target: types: [opened, reopened, ready_for_review, synchronize] - branches-ignore: - - "release-please--**" jobs: # Request review automatically when PRs are opened diff --git a/.github/workflows/luarocks.yaml b/.github/workflows/luarocks.yaml new file mode 100644 index 0000000..4dc366c --- /dev/null +++ b/.github/workflows/luarocks.yaml @@ -0,0 +1,21 @@ +name: luarocks + +on: + push: + tags: + - 'v*' + +jobs: + quality: + uses: ./.github/workflows/tests.yml + + publish: + needs: quality + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - uses: nvim-neorocks/luarocks-tag-release@v7 + env: + LUAROCKS_API_KEY: ${{ secrets.LUAROCKS_API_KEY }} diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 4ed3435..462bb8f 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -1,6 +1,7 @@ name: Tests on: + workflow_call: push: branches: - main @@ -69,27 +70,3 @@ jobs: - name: Run tests run: | bash ./run_tests.sh - - release: - name: release - - if: ${{ github.ref == 'refs/heads/main' }} - needs: - - luacheck - - stylua - - typecheck - - run_tests - runs-on: ubuntu-22.04 - steps: - - uses: googleapis/release-please-action@v4 - id: release - with: - release-type: simple - - uses: actions/checkout@v4 - - uses: rickstaa/action-create-tag@v1 - if: ${{ steps.release.outputs.release_created }} - with: - tag: stable - message: "Current stable release: ${{ steps.release.outputs.tag_name }}" - tag_exists_error: false - force_push_tag: true diff --git a/README.md b/README.md index 3734967..168f4fc 100644 --- a/README.md +++ b/README.md @@ -66,44 +66,58 @@ Neovim 0.8+ and optionally [mini.icons](https://github.com/nvim-mini/mini.nvim/b ## Installation -Install with your favorite package manager or with luarocks. +Install with your favorite package manager or with luarocks: -## Quick start - -Add the following to your init.lua - -```lua -require("oil").setup() +```console +luarocks install oil.nvim ``` -Then open a directory with `nvim .`. Use `` to open a file/directory, and `-` to go up a directory. Otherwise, just treat it like a normal buffer and make changes as you like. Remember to `:w` when you're done to actually perform the actions. - -If you want to mimic the `vim-vinegar` method of navigating to the parent directory of a file, add this keymap: - -```lua -vim.keymap.set("n", "-", "Oil", { desc = "Open parent directory" }) -``` - -You can open a directory with `:edit ` or `:Oil `. To open oil in a floating window, do `:Oil --float `. - ## Documentation -See `:help oil` for configuration, API reference, recipes, and more. +```vim +:help oil.nvim +``` ## FAQ -**Q: Why "oil"**? +**How do I migrate from `stevearc/oil.nvim` to `barrettruth/oil.nvim`?** -**A:** From the [vim-vinegar](https://github.com/tpope/vim-vinegar) README, a quote by Drew Neil: +Replace your `setup()` call with a `vim.g.oil` assignment. For example, with +[lazy.nvim](https://github.com/folke/lazy.nvim): + +```lua +-- before +{ + 'stevearc/oil.nvim', + config = function(_, opts) + require('oil').setup(opts) + end, + opts = { + ... + } +} + +-- after +{ + 'stevearc/oil.nvim', + init = function() + vim.g.oil = { + columns = { "icon", "size" }, + delete_to_trash = true, + } + end +``` + +**Why "oil"**? + +From the [vim-vinegar](https://github.com/tpope/vim-vinegar) README, a quote by Drew Neil: > Split windows and the project drawer go together like oil and vinegar Vinegar was taken. Let's be oil. Plus, I think it's pretty slick ;) -**Q: Why would I want to use oil vs any other plugin?** - -**A:** +**Why would I want to use oil vs any other plugin?** - You like to use a netrw-like view to browse directories (as opposed to a file tree) - AND you want to be able to edit your filesystem like a buffer @@ -111,14 +125,14 @@ Plus, I think it's pretty slick ;) If you don't need those features specifically, check out the alternatives listed below -**Q: Can oil display files as a tree view**? +**Can oil display files as a tree view**? -**A:** No. A tree view would require a completely different methodology, necessitating a complete rewrite. +No. A tree view would require a completely different methodology, necessitating a complete rewrite. -**Q: What are some alternatives?** - -**A:** +**What are some alternatives?** +- [the original](https://github.com/stevearc/oil.nvim): the lesser-maintained but + official `oil.nvim` - [mini.files](https://github.com/nvim-mini/mini.nvim/blob/main/readmes/mini-files.md): Also supports cross-directory filesystem-as-buffer edits with a column view. - [vim-vinegar](https://github.com/tpope/vim-vinegar): The granddaddy of single-directory file browsing. - [dirbuf.nvim](https://github.com/elihunter173/dirbuf.nvim): Edit filesystem like a buffer, but no cross-directory edits. diff --git a/doc/oil.txt b/doc/oil.txt index f6f7d14..431eff1 100644 --- a/doc/oil.txt +++ b/doc/oil.txt @@ -48,6 +48,27 @@ REQUIREMENTS *oil-requirement -------------------------------------------------------------------------------- CONFIG *oil-config* +Oil can be configured in two ways: + +1. The traditional `setup()` call: >lua + require("oil").setup({ + -- your opts here + }) +< + +2. Declarative configuration via `vim.g.oil`, which does not require calling + `setup()`: >lua + vim.g.oil = { + -- your opts here + } +< + + When `vim.g.oil` is set, oil initializes automatically during plugin + loading. If `setup()` is called with explicit opts, those take precedence + over `vim.g.oil`. + +The full list of options with their defaults: + >lua require("oil").setup({ -- Oil will take over directory buffers (e.g. `vim .` or `:e src/`) diff --git a/lua/oil/config.lua b/lua/oil/config.lua index 5c62b7e..3734bc0 100644 --- a/lua/oil/config.lua +++ b/lua/oil/config.lua @@ -406,7 +406,7 @@ local M = {} ---@field border? string|string[] Window border M.setup = function(opts) - opts = opts or {} + opts = opts or vim.g.oil or {} local new_conf = vim.tbl_deep_extend("keep", opts, default_config) if not new_conf.use_default_keymaps then diff --git a/plugin/oil.lua b/plugin/oil.lua new file mode 100644 index 0000000..2b1c352 --- /dev/null +++ b/plugin/oil.lua @@ -0,0 +1,3 @@ +if vim.g.oil ~= nil then + require("oil").setup() +end diff --git a/tests/config_spec.lua b/tests/config_spec.lua new file mode 100644 index 0000000..aac4eb1 --- /dev/null +++ b/tests/config_spec.lua @@ -0,0 +1,27 @@ +local config = require("oil.config") + +describe("config", function() + after_each(function() + vim.g.oil = nil + end) + + it("falls back to vim.g.oil when setup() is called with no args", function() + vim.g.oil = { delete_to_trash = true, cleanup_delay_ms = 5000 } + config.setup() + assert.is_true(config.delete_to_trash) + assert.equals(5000, config.cleanup_delay_ms) + end) + + it("uses defaults when neither opts nor vim.g.oil is set", function() + vim.g.oil = nil + config.setup() + assert.is_false(config.delete_to_trash) + assert.equals(2000, config.cleanup_delay_ms) + end) + + it("prefers explicit opts over vim.g.oil", function() + vim.g.oil = { delete_to_trash = true } + config.setup({ delete_to_trash = false }) + assert.is_false(config.delete_to_trash) + end) +end)