mirror of
https://github.com/LazyVim/LazyVim.git
synced 2025-07-16 04:14:37 +02:00
48 lines
1.5 KiB
Lua
48 lines
1.5 KiB
Lua
---@class lazyvim.util.terminal
|
|
---@overload fun(cmd: string|string[], opts: snacks.terminal.Opts): snacks.terminal
|
|
local M = setmetatable({}, {
|
|
__call = function(m, ...)
|
|
return m.open(...)
|
|
end,
|
|
})
|
|
|
|
---@param shell? string
|
|
function M.setup(shell)
|
|
vim.o.shell = shell or vim.o.shell
|
|
|
|
-- Special handling for pwsh
|
|
if shell == "pwsh" or shell == "powershell" then
|
|
-- Check if 'pwsh' is executable and set the shell accordingly
|
|
if vim.fn.executable("pwsh") == 1 then
|
|
vim.o.shell = "pwsh"
|
|
elseif vim.fn.executable("powershell") == 1 then
|
|
vim.o.shell = "powershell"
|
|
else
|
|
return LazyVim.error("No powershell executable found")
|
|
end
|
|
|
|
-- Setting shell command flags
|
|
vim.o.shellcmdflag =
|
|
"-NoLogo -ExecutionPolicy RemoteSigned -Command [Console]::InputEncoding=[Console]::OutputEncoding=[System.Text.UTF8Encoding]::new();$PSDefaultParameterValues['Out-File:Encoding']='utf8';"
|
|
|
|
-- Setting shell redirection
|
|
vim.o.shellredir = '2>&1 | %%{ "$_" } | Out-File %s; exit $LastExitCode'
|
|
|
|
-- Setting shell pipe
|
|
vim.o.shellpipe = '2>&1 | %%{ "$_" } | Tee-Object %s; exit $LastExitCode'
|
|
|
|
-- Setting shell quote options
|
|
vim.o.shellquote = ""
|
|
vim.o.shellxquote = ""
|
|
end
|
|
end
|
|
|
|
-- Opens a floating terminal (interactive by default)
|
|
---@deprecated use Snacks.terminal instead
|
|
---@param cmd? string[]|string
|
|
---@param opts? snacks.terminal.Opts
|
|
function M.open(cmd, opts)
|
|
return Snacks.terminal(cmd, opts)
|
|
end
|
|
|
|
return M
|