feat(lazyterm): optional shell setup, mainly for pwsh. Fixes #2151
This commit is contained in:
@ -12,6 +12,12 @@ vim.g.autoformat = true
|
||||
-- * a function with signature `function(buf) -> string|string[]`
|
||||
vim.g.root_spec = { "lsp", { ".git", "lua" }, "cwd" }
|
||||
|
||||
-- Optionally setup the terminal to use
|
||||
-- This sets `vim.o.shell` and does some additional configuration for:
|
||||
-- * pwsh
|
||||
-- * powershell
|
||||
-- LazyVim.terminal.setup("pwsh")
|
||||
|
||||
local opt = vim.opt
|
||||
|
||||
opt.autowrite = true -- Enable auto write
|
||||
|
@ -9,6 +9,37 @@ local M = setmetatable({}, {
|
||||
---@type table<string,LazyFloat>
|
||||
local terminals = {}
|
||||
|
||||
---@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
|
||||
|
||||
---@class LazyTermOpts: LazyCmdOptions
|
||||
---@field interactive? boolean
|
||||
---@field esc_esc? boolean
|
||||
|
Reference in New Issue
Block a user