当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 配置 VSCode PowerShell 终端

作者:精品下载站 日期:2024-12-14 07:49:21 浏览:14 分类:玩电脑

配置 VSCode PowerShell 终端


昨天,我发布了关于如何使用 PowerShell 终端会话设置最新版本 VSCode 的经验。正如我所解释的,在这个特定的会话中,我不想运行任何配置文件脚本。我的理由是,这个会话显然不是 ISE,我也不可能像使用传统控制台主机那样使用该会话。但是,我也意识到有些工具和设置对我有用。显然我不想在每次启动时手动配置 VSCode PowerShell 会话。它需要一个配置文件脚本。

由于 VS Code 只是运行 PowerShell.exe,因此没有新的配置文件选项。所以我创建了自己的。我编写了一个简单的 PowerShell 脚本,其中包含一些项目,以便我可以访问此终端中的工具和功能。以及定义该会话独有的变量。

#profile script for VS Code PowerShell session

Write-Host "Configuring VSCode PowerShell Terminal" -ForegroundColor Yellow

#dot source some useful commands and tools
. C:\scripts\Copy-HistoryCommand.ps1
. C:\scripts\Tee-MyObject.ps1
. C:\scripts\jdh-variables.ps1
. C:\scripts\jdh-psdrives.ps1
. C:\scripts\jdh-aliases.ps1
. C:\Scripts\Copy-Command\Copy-Command.ps1

#define some VSCode specific variables for future use.
$InVSCode = $True

这本质上是我的正常 PowerShell 配置文件脚本的精简变体。接下来,我修改了用于在 VSCode 中启动 PowerShell 的批处理文件。

::STARTPS.BAT
::This batch file is intended to start a PowerShell session
::as an integrated terminal window in VS Code

@echo off
::Force running the 64bit version of PowerShell
c:\windows\sysnative\WindowsPowerShell\v1.0\powershell.exe -nologo -noexit -noprofile -file c:\scripts\vscode-profile.ps1

我告诉 PowerShell 运行脚本文件,然后不退出。现在,当我在 VSCode 中启动 PowerShell 时,我得到如下结果:

[玩转系统] 配置 VSCode PowerShell 终端

我期待着探索如何在日常脚本开发中使用 VSCode。今天有一些限制,但我知道我们才刚刚开始,我很想知道我们的结局。

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯