无法使用VS Code命令从命令提示符中打开文件夹

时间:2019-08-11 20:51:58

标签: visual-studio-code

我希望能够使用现有命令通过命令提示符打开文件夹:

code . 

但是,每当我尝试在命令提示符下执行此命令时,它都会询问我要使用哪个程序打开文件。由于某种原因,该命令会打开一个文件,其中包含该exe的代码。

我检查了是否已设置正确的PATH,已卸载并重新安装了VS Code(同时确保在安装菜单中选择将VS Code自动添加到路径)。

这是我每次运行命令时显示的代码。

#!/usr/bin/env sh
#
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
COMMIT="036a6b1d3ac84e5ca96a17a44e63a87971f8fcc8"
APP_NAME="code"
QUALITY="stable"
NAME="Code"
DATAFOLDER=".vscode"
VSCODE_PATH="$(dirname "$(dirname "$(realpath "$0")")")"
ELECTRON="$VSCODE_PATH/$NAME.exe"
if grep -qi Microsoft /proc/version; then
    # in a wsl shell
    if [ "$WSL_DISTRO_NAME" ]; then
        # $WSL_DISTRO_NAME is available since WSL builds 18362, also for WSL2
        WSL_BUILD=18362
    else
        WSL_BUILD=$(uname -r | sed -E 's/^.+-([0-9]+)-Microsoft/\1/')
        if [ -z "$WSL_BUILD" ]; then
            WSL_BUILD=0
        fi
    fi

    if [ $WSL_BUILD -ge 17063 ]; then
        # $WSL_DISTRO_NAME is available since WSL builds 18362, also for WSL2
        # WSLPATH is available since WSL build 17046
        # WSLENV is available since WSL build 17063
        export WSLENV=ELECTRON_RUN_AS_NODE/w:$WSLENV
        CLI=$(wslpath -m "$VSCODE_PATH/resources/app/out/cli.js")

        # use the Remote WSL extension if installed
        WSL_EXT_ID="ms-vscode-remote.remote-wsl"
        WSL_EXT_WLOC=$(ELECTRON_RUN_AS_NODE=1 "$ELECTRON" "$CLI" --locate-extension $WSL_EXT_ID)
        if [ -n "$WSL_EXT_WLOC" ]; then
            # replace \r\n with \n in WSL_EXT_WLOC
            WSL_CODE=$(wslpath -u "${WSL_EXT_WLOC%%[[:cntrl:]]}")/scripts/wslCode.sh
            "$WSL_CODE" "$COMMIT" "$QUALITY" "$ELECTRON" "$APP_NAME" "$DATAFOLDER" "$@"
            exit $?
        fi
    else
        # If running under older WSL, don't pass cli.js to Electron as
        # environment vars cannot be transferred from WSL to Windows
        # See: https://github.com/Microsoft/BashOnWindows/issues/1363
        #      https://github.com/Microsoft/BashOnWindows/issues/1494
        "$ELECTRON" "$@"
        exit $?
    fi
elif [ -x "$(command -v cygpath)" ]; then
    CLI=$(cygpath -m "$VSCODE_PATH/resources/app/out/cli.js")
else
    CLI="$VSCODE_PATH/resources/app/out/cli.js"
fi
ELECTRON_RUN_AS_NODE=1 "$ELECTRON" "$CLI" "$@"
exit $?

我想发生的是,VS Code将打开我在其中执行命令的目录的文件夹。

0 个答案:

没有答案