diff --git a/doc/oil.txt b/doc/oil.txt index 450087b..449b7a8 100644 --- a/doc/oil.txt +++ b/doc/oil.txt @@ -240,6 +240,9 @@ close *actions.clos open_cmdline *actions.open_cmdline* Open vim cmdline with current entry as an argument +open_cmdline_dir *actions.open_cmdline_dir* + Open vim cmdline with current directory as an argument + open_cwd *actions.open_cwd* Open oil in Neovim's current working directory diff --git a/doc/tags b/doc/tags index 5a6b74e..b92023b 100644 --- a/doc/tags +++ b/doc/tags @@ -2,6 +2,7 @@ Oil oil.txt /*Oil* actions.cd oil.txt /*actions.cd* actions.close oil.txt /*actions.close* actions.open_cmdline oil.txt /*actions.open_cmdline* +actions.open_cmdline_dir oil.txt /*actions.open_cmdline_dir* actions.open_cwd oil.txt /*actions.open_cwd* actions.open_terminal oil.txt /*actions.open_terminal* actions.parent oil.txt /*actions.parent* diff --git a/lua/oil/actions.lua b/lua/oil/actions.lua index 967e68d..32b7bac 100644 --- a/lua/oil/actions.lua +++ b/lua/oil/actions.lua @@ -159,6 +159,16 @@ M.refresh = { end, } +local function open_cmdline_with_args(args) + local escaped = vim.api.nvim_replace_termcodes( + ": " .. args .. string.rep("", args:len() + 1), + true, + false, + true + ) + vim.api.nvim_feedkeys(escaped, "n", true) +end + M.open_cmdline = { desc = "Open vim cmdline with current entry as an argument", callback = function() @@ -171,18 +181,26 @@ M.open_cmdline = { end local bufname = vim.api.nvim_buf_get_name(0) local scheme, path = util.parse_url(bufname) + if not scheme then + return + end local adapter = config.get_adapter_by_scheme(scheme) if not adapter or not path or adapter.name ~= "files" then return end local fullpath = fs.shorten_path(fs.posix_to_os_path(path) .. entry.name) - local escaped = vim.api.nvim_replace_termcodes( - ": " .. fullpath .. string.rep("", fullpath:len() + 1), - true, - false, - true - ) - vim.api.nvim_feedkeys(escaped, "n", true) + open_cmdline_with_args(fullpath) + end, +} + +M.open_cmdline_dir = { + desc = "Open vim cmdline with current directory as an argument", + callback = function() + local fs = require("oil.fs") + local dir = oil.get_current_dir() + if dir then + open_cmdline_with_args(fs.shorten_path(dir)) + end end, }