-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathutils.lua
More file actions
40 lines (35 loc) · 1.5 KB
/
utils.lua
File metadata and controls
40 lines (35 loc) · 1.5 KB
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
31
32
33
34
35
36
37
38
39
40
-- General utils to keep init clean.
local M = {}
local is_windows = vim.uv.os_uname().sysname == "Windows_NT"
---Wrapper for jobstart.
---On windows, run it with {} so it doesn't spawn a shell.
---On unix, run it as string so it spawn a shell,
---so ENV is available, which is mandatory on termux.
---
---NOTE: In order to work on windows,
--- the executables must be added to path in at windows level.
---@param cmd string command to run.
---@param arguments table arguments to pass to the cmd.
---@param opts table vim.fn.jobstart options
---@return number job pid of the job, so we can stop it later.
M.jobstart = function(cmd, arguments, opts)
if is_windows then
return opts and vim.fn.jobstart({ cmd, unpack(arguments) }, opts) or vim.fn.jobstart({ cmd, unpack(arguments) })
else
return opts and vim.fn.jobstart(cmd .. " " .. table.concat(arguments, " "), opts) or vim.fn.jobstart(cmd .. " " .. table.concat(arguments, " "))
end
end
---We re-set the arguments we pass to markmap every time we run it to ensure
---they are always clean and correct, as every command get different ones.
---@return table arguments
M.reset_arguments = function()
local config = vim.g.markmap_config
local arguments = {}
if config.html_output ~= "" then -- if html_output is "", don't pass the parameter
table.insert(arguments, "-o")
table.insert(arguments, '"' .. config.html_output .. '"')
end
if config.hide_toolbar then table.insert(arguments, config.hide_toolbar) end
return arguments
end
return M