aboutsummaryrefslogtreecommitdiff
path: root/lua/muwiki/external.lua
blob: 9ea83b5e3de94815a57d48d94a8b00419a738209 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
local config = require('muwiki.config')
local paths = require('muwiki.paths')

local M = {}

function M.open(url)
  if type(url) ~= 'string' then
    vim.notify('Invalid URL type', vim.log.levels.ERROR)
    return false
  end

  local valid, err = paths.validate_url_scheme(url)
  if not valid then
    vim.notify(err, vim.log.levels.ERROR)
    return false
  end

  vim.system({ 'xdg-open', url }, { detach = true })
  return true
end

function M.execute(handler, url)
  if type(handler.cmd) == 'function' then
    handler.cmd(url)
  else
    vim.system({ handler.cmd, url }, { detach = true })
  end
end

return M