diff --git a/lua/orgmode/config/defaults.lua b/lua/orgmode/config/defaults.lua index 8b2397fae..d36e0e735 100644 --- a/lua/orgmode/config/defaults.lua +++ b/lua/orgmode/config/defaults.lua @@ -52,6 +52,17 @@ local DefaultConfig = { deadline_reminder = true, scheduled_reminder = true, }, + org_nontext_hyperlinks = false, + org_external_opener = 'xdg-open', + org_link_types = { + shell = { + handler = function(url) + url = string.gsub(url, '^shell:', '') + vim.fn.jobstart(url, { detach = true }) + return + end, + }, + }, mappings = { disable_all = false, prefix = 'o', diff --git a/lua/orgmode/org/mappings.lua b/lua/orgmode/org/mappings.lua index a2dc0e4e5..6325f53d9 100644 --- a/lua/orgmode/org/mappings.lua +++ b/lua/orgmode/org/mappings.lua @@ -754,6 +754,7 @@ function OrgMappings:open_at_point() local parts = vim.split(link, '][', true) local url = parts[1] local link_ctx = { base = url, skip_add_prefix = true } + if url:find('^file:') then if url:find(' +', 1, true) then parts = vim.split(url, ' +', true) @@ -766,6 +767,9 @@ function OrgMappings:open_at_point() if url:find('^file:(.-)::') then link_ctx.line = url + elseif config.org_nontext_hyperlinks and vim.filetype.match({ filename = url }) == nil then + local filepath = Hyperlinks.get_file_real_path(url) + vim.fn.jobstart(config.org_external_opener .. ' ' .. vim.fn.shellescape(filepath), { detach = true }) else vim.cmd(string.format('edit %s', Hyperlinks.get_file_real_path(url))) vim.cmd([[normal! zv]]) @@ -783,6 +787,12 @@ function OrgMappings:open_at_point() return vim.cmd(string.format('edit %s', url)) end + pref = string.gsub(url, '^(.-):.*', '%1') + if config.org_link_types[pref] ~= nil then + config.org_link_types[pref].handler(url) + return + end + local headlines = Hyperlinks.find_matching_links(link_ctx) local current_headline = Files.get_closest_headline() if current_headline then