我可以檢查終端機是否由 Visual Studio Code 啟動嗎?

我可以檢查終端機是否由 Visual Studio Code 啟動嗎?
  • 我將 VSCode 設定配置為在目前工作區資料夾中啟動整合終端(使用 Powershell):

    "terminal.integrated.cwd": "${workspaceFolder}"


  • 當我在 VSCode 之外啟動與 VSCode 無關的 Powershell 視窗時,我希望預設啟動目錄是我的使用者設定檔。我的 Powershell 設定檔配置為預設在我的主目錄 (C:\Users\stvhwrd) 中啟動:

    Set-Location -Path "${env:USERPROFILE}"


當我在 VSCode 中打開整合終端時,設定檔設定優先於 VSCode 設置,因此整合終端始終在我的使用者設定檔目錄中啟動。這很煩人,因為我需要cd通過多個層級才能到達當前專案的目錄。

如何配置以便整合終端將在當前專案目錄中啟動,而外部[獨立]終端將在我的使用者設定檔中啟動?

受到這個 AskUbuntu 問題的啟發

答案1

編輯您的 Powershell 設定檔:

notepad $profile

新增條件檢查VSCode 設定的終端環境鍵啟動時:

# Set default directory
if ("${env:VSCODE_CWD}" -or "${env:TERM_PROGRAM}" -eq "vscode")
{
    # Allow VSCode settings to determine directory
}
else
{
    Set-Location -Path "${env:USERPROFILE}"
}

受到這個 AskUbuntu 問題的啟發

相關內容