refactor: rework Oil command to support --float argument anywhere

This commit is contained in:
Steven Arcangeli 2023-01-04 00:34:01 -08:00
parent a0b69fa117
commit 101689b0fe
2 changed files with 10 additions and 11 deletions

View file

@ -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" }) vim.keymap.set("n", "-", require("oil").open, { desc = "Open parent directory" })
``` ```
You can also use the `Oil` command to open oil.nvim. You can open a directory with `:edit <path>` or `:Oil <path>`. To open oil in a floating window, do `:Oil --float <path>`.
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.
## Options ## Options

View file

@ -498,16 +498,16 @@ M.setup = function(opts)
config.setup(opts) config.setup(opts)
set_colors() set_colors()
vim.api.nvim_create_user_command("Oil", function(args) vim.api.nvim_create_user_command("Oil", function(args)
if #args.fargs == 0 then local float = false
require("oil").open() for i, v in ipairs(args.fargs) do
elseif args.fargs[1] == "--float" then if v == "--float" then
require("oil").open_float() float = true
elseif args.fargs[2] == "--float" then table.remove(args.fargs, i)
require("oil").open_float(args.fargs[1]) end
else
require("oil").open(args.fargs[1])
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", {}) local aug = vim.api.nvim_create_augroup("Oil", {})
if vim.fn.exists("#FileExplorer") then if vim.fn.exists("#FileExplorer") then
vim.api.nvim_create_augroup("FileExplorer", { clear = true }) vim.api.nvim_create_augroup("FileExplorer", { clear = true })