Windows终端-使用不同的配置文件启动powershell

Windows终端-使用不同的配置文件启动powershell,powershell,powershell-core,windows-terminal,Powershell,Powershell Core,Windows Terminal,如何将windows终端配置为使用标准$配置文件以外的单独配置文件启动Powershell 这将有助于仅在我从wt.exe而不是从pwsh.exe启动的Powershell实例中导入posh git和psreadline等模块。您可以在从wt.exe调用pwsh.exe或Powershell.exe时,从中获取自定义Powershell.ps1配置文件。例如,Windows Terminal settings.json中的posh git配置文件如下所示: { "guid&qu

如何将windows终端配置为使用标准$配置文件以外的单独配置文件启动Powershell


这将有助于仅在我从wt.exe而不是从pwsh.exe启动的Powershell实例中导入posh git和psreadline等模块。您可以在从wt.exe调用pwsh.exe或Powershell.exe时,从中获取自定义Powershell.ps1配置文件。例如,Windows Terminal 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至少看起来像这样:

导入模块posh git 函数全局:提示 { 写入主机-对象Posh Git-NoNewline-ForegroundColor品红 返回> }
除了$Profile中默认的配置文件外,您是否已经安装了Powershell以运行其他配置文件?如果没有,请查看。在较新的WT.exe设置gui中,我将其放在命令行下:%ProgramFiles%\PowerShell\7\pwsh.exe-noexit-noprofile-f%USERPROFILE%\GIT\u profile.ps1