Windows 终端 - 使用不同的配置文件启动 powershell
Windows Terminal - Launch powershell with different profile
如何配置 windows 终端以使用我的标准 $Profile
以外的单独配置文件启动 Powershell
这将有助于仅在我从 wt.exe
而不是从 pwsh.exe
[=16 启动的 Powershell 实例中导入像 posh-git
和 psreadline
这样的模块=]
您可以在从 wt.exe
调用 pwsh.exe
或 powershell.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 "> "
}
如何配置 windows 终端以使用我的标准 $Profile
这将有助于仅在我从 wt.exe
而不是从 pwsh.exe
[=16 启动的 Powershell 实例中导入像 posh-git
和 psreadline
这样的模块=]
您可以在从 wt.exe
调用 pwsh.exe
或 powershell.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 "> "
}