mirror of
https://github.com/neovim/neovim.git
synced 2026-06-17 17:21:16 +00:00
fix(option): set 'shell…' options based on detected shell #40031
Problem: * 'shellcmdflag' states that its default value is set according to the value of 'shell', but this behavior is not yet implemented on Windows. The same applies to 'shellpipe', 'shellredir', and 'shellxquote'. * On Windows, Git is often installed in paths containing spaces, and we still do not correctly resolve the sh executable name as described in 'shell'. * On Windows, the default value of 'shellslash' is always `false`, which causes Unix-like shells to interpret `\` in paths returned by some functions as escape charaters. Solution: Use a simple rule table to detect common shells (e.g. `cmd`, `powershell`, shells whose names contain `csh` or `sh`) and apply best-effort defaults, while leaving more complex scenarios to user configuration.
This commit is contained in:
78
test/functional/options/shell_spec.lua
Normal file
78
test/functional/options/shell_spec.lua
Normal file
@@ -0,0 +1,78 @@
|
||||
local t = require('test.testutil')
|
||||
local n = require('test.functional.testnvim')()
|
||||
|
||||
local eq = t.eq
|
||||
local is_os = t.is_os
|
||||
local skip = t.skip
|
||||
local api = n.api
|
||||
local clear = n.clear
|
||||
|
||||
describe('applies sensible default options for different shells #28384', function()
|
||||
---@param sh string
|
||||
---@param shcf string
|
||||
---@param sp string
|
||||
---@param srr string
|
||||
---@param sxq string
|
||||
---@param ssl boolean
|
||||
local function expect(sh, shcf, sp, srr, sxq, ssl)
|
||||
local opt = { sh = sh, shcf = shcf, sp = sp, srr = srr, sxq = sxq, ssl = ssl }
|
||||
for k, v in pairs(opt) do
|
||||
eq(v, api.nvim_get_option_info2(k, {}).default)
|
||||
end
|
||||
end
|
||||
it('cmd.exe', function()
|
||||
skip(not is_os('win'), 'N/A: only works on Windows')
|
||||
clear()
|
||||
expect('cmd.exe', '/s /c', '2>&1| tee', '>%s 2>&1', '"', false)
|
||||
end)
|
||||
|
||||
it('powershell(PowerShell 5.x)', function()
|
||||
t.skip(not is_os('win'), 'N/A: only works on Windows')
|
||||
clear {
|
||||
env = { SHELL = 'powershell' },
|
||||
}
|
||||
expect('powershell', '-Command', '2>&1| tee', '>%s 2>&1', '', true)
|
||||
end)
|
||||
|
||||
it('pwsh(PowerShell 7.x)', function()
|
||||
clear {
|
||||
env = { SHELL = 'pwsh' },
|
||||
}
|
||||
expect('pwsh', '-c', '2>&1| tee', '>%s 2>&1', '', true)
|
||||
end)
|
||||
|
||||
it('csh', function()
|
||||
clear {
|
||||
env = { SHELL = 'csh' },
|
||||
}
|
||||
expect('csh', '-c', '|& tee', '>&', '', true)
|
||||
end)
|
||||
|
||||
it('bash', function()
|
||||
clear {
|
||||
env = { SHELL = 'bash' },
|
||||
}
|
||||
expect('bash', '-c', '2>&1| tee', '>%s 2>&1', '', true)
|
||||
end)
|
||||
|
||||
it('unknown', function()
|
||||
clear {
|
||||
env = { SHELL = 'unknown' },
|
||||
}
|
||||
expect(
|
||||
'unknown',
|
||||
'-c',
|
||||
not is_os('win') and '| tee' or '2>&1| tee',
|
||||
not is_os('win') and '>' or '>%s 2>&1',
|
||||
'',
|
||||
not is_os('win') and true or false
|
||||
)
|
||||
end)
|
||||
|
||||
it('even if the path contains spaces', function()
|
||||
clear {
|
||||
env = { SHELL = ('%s/foo bar/bash'):format(n.nvim_dir) },
|
||||
}
|
||||
expect(('"%s/foo bar/bash"'):format(n.nvim_dir), '-c', '2>&1| tee', '>%s 2>&1', '', true)
|
||||
end)
|
||||
end)
|
||||
Reference in New Issue
Block a user