robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Justin M. KeyesMerge #41088 from barrettruth/feat/zip-health-encryption794886aae7

master
1.6 KiB60 linesraw
1local M = {}
2
3local health = vim.health
4
5local function check_backend()
6  health.start('nvim.zip: backend')
7
8  local exe = vim.fn.exepath('unzip')
9  if exe == '' then
10    health.error('`unzip` executable not found', {
11      'Install Info-ZIP `unzip` to browse and read archives.',
12      'Or `:packadd old-zip` to use the legacy plugin.',
13    })
14    return
15  end
16
17  local out = vim.system({ exe, '-v' }, { text = true }):wait()
18  local version = vim.split(out.stdout or '', '\n')[1] or ''
19  health.ok(('`unzip` found: %s'):format(exe))
20  if version ~= '' then
21    health.info(version)
22  end
23end
24
25--- @return boolean Whether an implementation that needs the backend is handling archives.
26local function check_active()
27  health.start('nvim.zip: active implementation')
28
29  local legacy = vim.fn.exists('#zip') == 1
30  local builtin = vim.fn.exists('#nvim.zip') == 1
31
32  if legacy then
33    health.info('`old-zip` is loaded, so it handles archives instead of zip.lua')
34    health.info('zip.lua defers to it while it is loaded')
35    -- `old-zip` shells out to the same backend.
36    return true
37  end
38
39  if not builtin then
40    if vim.g.loaded_nvim_zip_plugin ~= nil then
41      health.info('Disabled (`g:loaded_nvim_zip_plugin` is set).')
42    else
43      health.warn('No zip plugin is active')
44    end
45    return false
46  end
47
48  health.ok('zip.lua is active')
49  return true
50end
51
52function M.check()
53  -- Report the backend only when something is actually going to run it, so that disabling the
54  -- plugin does not report a missing `unzip` as an error.
55  if check_active() then
56    check_backend()
57  end
58end
59
60return M