【问题标题】:Open Visual Studio Code Powershell Terminal in script folder在脚本文件夹中打开 Visual Studio Code Powershell 终端
【发布时间】:2017-11-04 18:32:05
【问题描述】:

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

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

【问题讨论】:

    标签: powershell visual-studio-code


    【解决方案1】:

    假设:

    • 您已将 PowerShell 配置为默认 shell - 通过命令 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 作为默认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\"'" ]
    

    【讨论】:

      猜你喜欢
      • 2018-02-16
      • 2021-05-12
      • 1970-01-01
      • 2017-05-13
      • 2023-02-02
      • 2020-06-30
      • 1970-01-01
      • 2019-05-18
      • 1970-01-01
      相关资源
      最近更新 更多