在 VSCode 集成终端内运行时如何自定义 powershell? [英] How can I customize powershell when running inside of the VSCode integrated terminal?
问题描述
我想包含一些仅在 VSCode 内部运行时才会发生的 Powershell 自定义.
I would like to include a few Powershell customizations that only occur when running inside of VSCode.
在 ISE 或包管理控制台内(在 Visual Studio 内)时,我可以使用 $host.name
的值来切换行为或在主机特定"powershell 配置文件中包含特定代码(例如Microsoft.PowerShell_profile.ps1
).
When inside of ISE or Package Management Console (inside Visual Studio), I can use the value of $host.name
to switch behavior or include specific code in the "host specific" powershell profile (e.g. Microsoft.PowerShell_profile.ps1
).
VSCode 中的 Powershell 看起来与在常规控制台中运行的 Powershell 相同,因此这些选项中的大多数都不可用.有没有办法解决这个问题?
Powershell inside of VSCode appears identical to Powershell running in a regular console so most of these options aren't available. Is there anyway to workaround this?
推荐答案
VSCode 在其集成终端中将 TERM_PROGRAM
环境变量设置为 vscode
,因此您可以使用以下内容测试,无论是否安装了 PowerShell 扩展都有效:
VSCode sets the TERM_PROGRAM
environment variable to vscode
in its integrated terminal, so you can use the following test, which works whether or not the PowerShell extension is installed:
$runningInVsCode = $env:TERM_PROGRAM -eq 'vscode'
这篇关于在 VSCode 集成终端内运行时如何自定义 powershell?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!