commit 0faf007a236c9b51f151790f79ee59366b501c55
parent ef1d291f29961ae10cc122e92fb2419cbbd29f3b
Author: euclidianAce <euclidianAce@protonmail.com>
Date: Wed, 9 Nov 2022 17:26:02 -0600
fix(man.lua): use `env` command (#21007)
Previously man.lua would use the `env` field in the parameters of
`vim.loop.spawn` to override things like MANPAGER. This caused issues on
NixOS since `spawn` will _override_ the environment rather than _append_
to it (and NixOS relies on a heavily modified environment). Using the
`env` command to append to the environment solves this issue.
Diffstat:
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/runtime/lua/man.lua b/runtime/lua/man.lua
@@ -12,7 +12,7 @@ local function man_error(msg)
end
-- Run a system command and timeout after 30 seconds.
-local function system(cmd, silent, env)
+local function system(cmd_, silent, env)
local stdout_data = {}
local stderr_data = {}
local stdout = vim.loop.new_pipe(false)
@@ -21,11 +21,23 @@ local function system(cmd, silent, env)
local done = false
local exit_code
+ -- We use the `env` command here rather than the env option to vim.loop.spawn since spawn will
+ -- completely overwrite the environment when we just want to modify the existing one.
+ --
+ -- Overwriting mainly causes problems NixOS which relies heavily on a non-standard environment.
+ local cmd
+ if env then
+ cmd = { 'env' }
+ vim.list_extend(cmd, env)
+ vim.list_extend(cmd, cmd_)
+ else
+ cmd = cmd_
+ end
+
local handle
handle = vim.loop.spawn(cmd[1], {
args = vim.list_slice(cmd, 2),
stdio = { nil, stdout, stderr },
- env = env,
}, function(code)
exit_code = code
stdout:close()