gpt4 book ai didi

powershell - 在脚本文件夹中打开 Visual Studio Code Powershell 终端

转载 作者:行者123 更新时间:2023-12-02 18:49:42 28 4
gpt4 key购买 nike

当我在 VSCode 中右键单击 ps1 脚本并在 Powershell 终端中打开它时,当前文件夹不是脚本文件夹,而是项目文件夹。

有没有办法将其配置为在脚本文件夹中打开?

最佳答案

假设:

  • 您已将 PowerShell 配置为默认 shell - 通过命令终端:选择默认 Shell(在 Windows 上)或直接通过用户设置 “terminal.integrated.shell.windows”/“terminal.integrated.shell.osx”/“terminal.integrated.shell.linux”

  • 您正在尝试通过右键单击侧边栏的资源管理器 View 中的文件/子文件夹并选择在终端中打开来打开 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 作为默认 shell,然后使用显式更改为该文件夹的命令调用 PowerShell。

以下其他平台的解决方法类似:

ma​​cOS 上:

"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\"'" ]

关于powershell - 在脚本文件夹中打开 Visual Studio Code Powershell 终端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47114160/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com