Skip to content

Commit cbcb3f9

Browse files
authored
fix: command modifiers for :Oil (#691)
* Support command mods `:belowright hor 10Oil` * Fix `:tab Oil` only work on the first tab
1 parent b9ab05f commit cbcb3f9

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

lua/oil/init.lua

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,9 +1128,9 @@ M.setup = function(opts)
11281128

11291129
config.setup(opts)
11301130
set_colors()
1131-
vim.api.nvim_create_user_command("Oil", function(args)
1131+
local callback = function(args)
11321132
local util = require("oil.util")
1133-
if args.smods.tab == 1 then
1133+
if args.smods.tab > 0 then
11341134
vim.cmd.tabnew()
11351135
end
11361136
local float = false
@@ -1163,11 +1163,11 @@ M.setup = function(opts)
11631163
end
11641164
end
11651165

1166-
if not float and (args.smods.vertical or args.smods.split ~= "") then
1166+
if not float and (args.smods.vertical or args.smods.horizontal or args.smods.split ~= "") then
11671167
if args.smods.vertical then
1168-
vim.cmd.vsplit({ mods = { split = args.smods.split } })
1168+
vim.cmd.vsplit({ mods = { split = args.smods.split }, range = { args.count } })
11691169
else
1170-
vim.cmd.split({ mods = { split = args.smods.split } })
1170+
vim.cmd.split({ mods = { split = args.smods.split }, range = { args.count } })
11711171
end
11721172
end
11731173

@@ -1183,7 +1183,12 @@ M.setup = function(opts)
11831183
open_opts.preview = {}
11841184
end
11851185
M[method](path, open_opts)
1186-
end, { desc = "Open oil file browser on a directory", nargs = "*", complete = "dir" })
1186+
end
1187+
vim.api.nvim_create_user_command(
1188+
"Oil",
1189+
callback,
1190+
{ desc = "Open oil file browser on a directory", nargs = "*", complete = "dir", count = true }
1191+
)
11871192
local aug = vim.api.nvim_create_augroup("Oil", {})
11881193

11891194
if config.default_file_explorer then

0 commit comments

Comments
 (0)