Skip to content

Commit

Permalink
Remove <leader>o, use gx instead
Browse files Browse the repository at this point in the history
  • Loading branch information
Jendker committed Aug 22, 2024
1 parent fbf8c26 commit e28eba6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
33 changes: 21 additions & 12 deletions nvim/lua/common.lua
Original file line number Diff line number Diff line change
Expand Up @@ -150,23 +150,32 @@ M.getGitRoot = function()
return git_root
end

M.getSystemCommand = function()
local system_name = vim.uv.os_uname().sysname
if system_name == "Darwin" then
return "open"
elseif system_name == "Linux" then
return "xdg-open"
local function get_open_cmd(path)
if vim.fn.has("mac") == 1 then
return { "open", path }
elseif vim.fn.executable("xdg-open") == 1 then
return { "xdg-open", path }
elseif vim.fn.has("win32") == 1 then
if vim.fn.executable("rundll32") == 1 then
return { "rundll32", "url.dll,FileProtocolHandler", path }
else
return nil, "rundll32 not found"
end
elseif vim.fn.executable("explorer.exe") == 1 then
return { "explorer.exe", path }
else
return nil, "no handler found"
end
vim.api.nvim_err_writeln("System not known: " .. system_name)
return nil
end

M.openWithDefault = function(text)
local command = M.getSystemCommand()
if command == nil then
M.openWithDefault = function(path)
local cmd, err = get_open_cmd(path)
if not cmd then
vim.notify(string.format("Could not open %s: %s", path, err), vim.log.levels.ERROR)
return
end
vim.fn.jobstart(command .. " " .. text)
local jid = vim.fn.jobstart(cmd, { detach = true })
assert(jid > 0, "Failed to start job")
end

M.getTableIndex = function(tab, val)
Expand Down
3 changes: 0 additions & 3 deletions nvim/lua/keymaps.lua
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,6 @@ map("n", "<leader>qq", "<cmd>qa<cr>", { desc = "Quit all" })
map("n", "j", [[(v:count > 5 ? "m'" . v:count . 'j' : 'gj')]], { expr = true })
map("n", "k", [[(v:count > 5 ? "m'" . v:count . 'k' : 'gk')]], { expr = true })

map('n', '<leader>o', function() common.openWithDefault(vim.fn.expand('<cWORD>')) end, { desc = "Open with default application" })
map('v', '<leader>o', function() common.openWithDefault(common.getVisualSelection()) end, { desc = "Open with default application" })

local function type_no_escape(text)
vim.api.nvim_feedkeys(text, "n", false)
end
Expand Down

0 comments on commit e28eba6

Please sign in to comment.