LazyVim.LazyVim/lua/lazyvim/util/terminal.lua

49 lines
1.5 KiB
Lua
Raw Normal View History

---@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)
2024-11-03 23:03:19 +01:00
---@deprecated use Snacks.terminal instead
---@param cmd? string[]|string
---@param opts? snacks.terminal.Opts
function M.open(cmd, opts)
2024-11-03 23:03:19 +01:00
return Snacks.terminal(cmd, opts)
end
return M