From 101689b0feff95d396100501134c7316bb949062 Mon Sep 17 00:00:00 2001 From: Steven Arcangeli Date: Wed, 4 Jan 2023 00:34:01 -0800 Subject: [PATCH] refactor: rework Oil command to support --float argument anywhere --- README.md | 3 +-- lua/oil/init.lua | 18 +++++++++--------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 5ecfe43..2f7b2f1 100644 --- a/README.md +++ b/README.md @@ -103,8 +103,7 @@ If you want to mimic the `vim-vinegar` method of navigating to the parent direct vim.keymap.set("n", "-", require("oil").open, { desc = "Open parent directory" }) ``` -You can also use the `Oil` command to open oil.nvim. -You can provide a folder argument to open this folder and add `--float` at the end of the command to open oil in a float. +You can open a directory with `:edit ` or `:Oil `. To open oil in a floating window, do `:Oil --float `. ## Options diff --git a/lua/oil/init.lua b/lua/oil/init.lua index ec0ca73..2cc9216 100644 --- a/lua/oil/init.lua +++ b/lua/oil/init.lua @@ -498,16 +498,16 @@ M.setup = function(opts) config.setup(opts) set_colors() vim.api.nvim_create_user_command("Oil", function(args) - if #args.fargs == 0 then - require("oil").open() - elseif args.fargs[1] == "--float" then - require("oil").open_float() - elseif args.fargs[2] == "--float" then - require("oil").open_float(args.fargs[1]) - else - require("oil").open(args.fargs[1]) + local float = false + for i, v in ipairs(args.fargs) do + if v == "--float" then + float = true + table.remove(args.fargs, i) + end end - end, { nargs = "*", complete = "dir" }) + local method = float and "open_float" or "open" + M[method](unpack(args.fargs)) + end, { desc = "Open oil file browser on a directory", nargs = "*", complete = "dir" }) local aug = vim.api.nvim_create_augroup("Oil", {}) if vim.fn.exists("#FileExplorer") then vim.api.nvim_create_augroup("FileExplorer", { clear = true })