【问题标题】:Windows Terminal - Launch powershell with different profileWindows 终端 - 使用不同的配置文件启动 powershell
【发布时间】:2020-10-22 00:26:20
【问题描述】:

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

这将有助于在我从 wt.exe 而不是从 pwsh.exe 启动的 Powershell 实例中导入像 posh-gitpsreadline 这样的模块

【问题讨论】:

  • 您是否已经安装了 Powershell 来运行 $Profile 中默认的配置文件以外的配置文件?如果没有,请参阅here

标签: powershell powershell-core windows-terminal


【解决方案1】:

您可以在从wt.exe 调用pwsh.exepowershell.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 "> "
}

【讨论】:

  • 在较新的 WT.exe 设置 gui 中,我将其放在 command line:%ProgramFiles%\PowerShell\7\pwsh.exe -noexit -noprofile -f %USERPROFILE%\GIT_profile.ps1
猜你喜欢
  • 2022-10-17
  • 1970-01-01
  • 1970-01-01
  • 2020-08-18
  • 2017-07-17
  • 2018-03-02
  • 1970-01-01
  • 2021-01-07
  • 2020-09-07
相关资源
最近更新 更多