diff --git a/lua/oil/actions.lua b/lua/oil/actions.lua index b97ae37..21b175a 100644 --- a/lua/oil/actions.lua +++ b/lua/oil/actions.lua @@ -30,6 +30,13 @@ M.select_split = { end, } +M.select_tab = { + desc = "Open the entry under the cursor in a new tab", + callback = function() + oil.select({ tab = true }) + end, +} + M.preview = { desc = "Open the entry under the cursor in a preview window, or close the preview window if already open", callback = function() diff --git a/lua/oil/config.lua b/lua/oil/config.lua index 1f9b133..5c63c8e 100644 --- a/lua/oil/config.lua +++ b/lua/oil/config.lua @@ -37,6 +37,7 @@ local default_config = { [""] = "actions.select", [""] = "actions.select_vsplit", [""] = "actions.select_split", + [""] = "actions.select_tab", [""] = "actions.preview", [""] = "actions.close", [""] = "actions.refresh", diff --git a/lua/oil/init.lua b/lua/oil/init.lua index 0592cf2..c4364a0 100644 --- a/lua/oil/init.lua +++ b/lua/oil/init.lua @@ -313,6 +313,7 @@ end --- horizontal boolean Open the buffer in a horizontal split --- split "aboveleft"|"belowright"|"topleft"|"botright" Split modifier --- preview boolean Open the buffer in a preview window +--- tab boolean Open the buffer in a new tab M.select = function(opts) local cache = require("oil.cache") opts = vim.tbl_extend("keep", opts or {}, {}) @@ -322,6 +323,9 @@ M.select = function(opts) if opts.preview and not opts.horizontal and opts.vertical == nil then opts.vertical = true end + if opts.tab and (opts.preview or opts.split) then + error("Cannot set preview or split when tab = true") + end local util = require("oil.util") if util.is_floating_win() and opts.preview then vim.notify("oil preview doesn't work in a floating window", vim.log.levels.ERROR) @@ -405,7 +409,14 @@ M.select = function(opts) if vim.tbl_isempty(mods) then mods = nil end - local cmd = opts.split and "split" or "edit" + local cmd + if opts.tab then + cmd = "tabedit" + elseif opts.split then + cmd = "split" + else + cmd = "edit" + end vim.cmd({ cmd = cmd, args = { url }, diff --git a/tests/altbuf_spec.lua b/tests/altbuf_spec.lua index 03846e0..0c319af 100644 --- a/tests/altbuf_spec.lua +++ b/tests/altbuf_spec.lua @@ -76,7 +76,7 @@ a.describe("Alternate buffer", function() oil.open_float() test_util.wait_for_autocmd("BufReadPost") -- This is lazy, but testing the actual select logic is more difficult. We can simply - -- replicated it by closing the current window and then doing the edit + -- replicate it by closing the current window and then doing the edit vim.api.nvim_win_close(0, true) vim.cmd.edit({ args = { "bar" } }) assert.equals("foo", vim.fn.expand("#")) @@ -88,7 +88,7 @@ a.describe("Alternate buffer", function() oil.open_float() test_util.wait_for_autocmd("BufReadPost") -- This is lazy, but testing the actual select logic is more difficult. We can simply - -- replicated it by closing the current window and then doing the edit + -- replicate it by closing the current window and then doing the edit vim.api.nvim_win_close(0, true) vim.cmd.edit({ args = { "bar" } }) assert.equals("foo", vim.fn.expand("#")) diff --git a/tests/url_spec.lua b/tests/url_spec.lua index 43d5b3d..fbdde90 100644 --- a/tests/url_spec.lua +++ b/tests/url_spec.lua @@ -4,6 +4,7 @@ describe("url", function() it("get_url_for_path", function() local cases = { { "", "oil://" .. util.addslash(vim.fn.getcwd()) }, + { "term://~/oil.nvim//52953:/bin/bash", "oil://" .. vim.loop.os_homedir() .. "/oil.nvim/" }, { "/foo/bar.txt", "oil:///foo/", "bar.txt" }, { "oil:///foo/bar.txt", "oil:///foo/", "bar.txt" }, { "oil:///", "oil:///" },