簡體   English   中英

在腳本文件夾中打開Visual Studio Code Powershell終端

[英]Open Visual Studio Code Powershell Terminal in script folder

當我右鍵單擊VSCode中的ps1腳本並在Powershell Terminal中打開它時,當前文件夾不是腳本文件夾,而是項目文件夾。

有沒有一種方法可以配置它在腳本文件夾中打開?

假設:

  • 您已將PowerShell配置為默認外殼 -通過命令“ Terminal: Select Default Shell (在Windows上)或直接通過用戶設置"terminal.integrated.shell.windows" / "terminal.integrated.shell.osx" / "terminal.integrated.shell.linux"

  • 您試圖通過右鍵單擊側欄的Explorer視圖中的文件/子文件夾並選擇“ Open in Terminal來打開PowerShell實例,並且希望該實例的當前位置為該文件所在的文件夾/該子文件夾

從(至少)VSCode 1.17.2開始, 默認情況下應該可以使用

如果不是這樣,則$PROFILE自定義代碼可能會直接或間接更改當前位置

如果您不希望/無法阻止$PROFILE代碼更改位置,請采用以下解決方法,通過用戶設置在$PROFILE代碼運行 顯式設置當前位置

Windows上

"terminal.integrated.shell.windows": "cmd.exe",
"terminal.integrated.shellArgs.windows": [ "/c", "powershell -noexit -command 'Set-location \"%CD%\"'" ]

這使用cmd.exe作為默認外殼程序,然后使用一個明確將其更改為該文件夾的命令來調用PowerShell。

以下其他平台的解決方法類似地起作用:

macOS上

"terminal.integrated.shell.osx": "/bin/bash",
"terminal.integrated.shellArgs.osx": [ "-l", "-c", "exec pwsh -noexit -command 'set-location \"$PWD\"'" ]

Linux上

"terminal.integrated.shell.linux": "/bin/bash",
"terminal.integrated.shellArgs.linux": [ "-c", "exec pwsh -noexit -command 'set-location \"$PWD\"'" ]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM