Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions lua/oil/actions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,47 @@ M.open_external = {
end,
}

local programs = {
{ name = "xdg-open (default)", cmd = function(path) return { "xdg-open", path } end },
{ name = "Chrome", cmd = function(path) return { "google-chrome", path } end },
{ name = "Okular", cmd = function(path) return { "okular", path } end },
{ name = "Firefox", cmd = function(path) return { "firefox", path } end },
{ name = "VLC", cmd = function(path) return { "vlc", path } end },
{ name = "Open with custom…", cmd = "custom" },
}

local function pick_and_open(path)
vim.ui.select(programs, {
prompt = "Open with:",
format_item = function(it) return it.name end,
}, function(choice)
if not choice then return end

if choice.cmd == "custom" then
vim.ui.input({ prompt = "Program: " }, function(prog)
if not prog or prog == "" then return end
vim.fn.jobstart({ prog, path }, { detach = true })
end)
return
end

local cmd = choice.cmd(path)
vim.fn.jobstart(cmd, { detach = true })
end)
end

M.open_external_select = {
desc = "Open the entry under the cursor in an external program selection",
callback = function()
local entry = oil.get_cursor_entry()
local dir = oil.get_current_dir()
if not entry or not dir then return end

local path = dir .. entry.name
pick_and_open(path)
end,
}

M.refresh = {
desc = "Refresh current directory list",
callback = function(opts)
Expand Down
1 change: 1 addition & 0 deletions lua/oil/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ local default_config = {
["g~"] = { "actions.cd", opts = { scope = "tab" }, mode = "n" },
["gs"] = { "actions.change_sort", mode = "n" },
["gx"] = "actions.open_external",
["gX"] = "actions.open_external_select",
["g."] = { "actions.toggle_hidden", mode = "n" },
["g\\"] = { "actions.toggle_trash", mode = "n" },
},
Expand Down