Windows Terminal - 使用不同的配置文件启动 PowerShell

7

如何配置Windows终端以使用与我的标准$Profile不同的单独配置文件启动Powershell?


这对于在从wt.exe而不是pwsh.exe启动的Powershell实例中导入posh-gitpsreadline等模块非常有用。


你是否已经设置了PowerShell以运行除$Profile默认文件之外的其他配置文件?如果没有,请参见此处 - apena
1个回答

6

当您调用pwsh.exepowershell.exe来自wt.exe时,可以作为来源引用自定义Powershell (.ps1)配置文件。例如,在Windows终端settings.json中设置一个posh-git配置文件可能如下所示:

{
    "guid": "{01463d52-dda9-4109-b03f-c55899b52df2}",
    "name": "Powershell - Posh Git",
    "commandline": "powershell.exe -noprofile -noexit -command \"invoke-expression '. ''C:/PsProfilePoshGit.ps1''' \"",
    "icon": "ms-appx:///ProfileIcons/{61c54bbd-c2c6-5271-96e7-009a87ff44bf}.png",
    "hidden": false
},

通过在Powershell中运行命令[guid]::NewGuid(),您可以为每个新概要生成一个唯一的GUID。

最后,您的专用Powershell概要文件:C:/PsProfilePoshGit.ps1应该至少看起来像这样:

Import-Module posh-git
function global:prompt
{
    Write-Host -Object "Posh-Git" -NoNewline -ForegroundColor Magenta
 
    return "> "
}

6
在更新的WT.exe设置图形用户界面中,我将以下内容放在“命令行”下方:%ProgramFiles%\PowerShell\7\pwsh.exe -noexit -noprofile -f %USERPROFILE%\GIT_profile.ps1 - Hicsy

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接