在Windows 10上运行VSCode任务时无法加载.bash_profile或.bashrc

时间:2019-02-07 11:42:42

标签: windows bash shell terminal visual-studio-code

我正在Windows 10 Home上使用VSCode1.31.0。我已启用WSL,并安装了nvm,pyenv等工具,这需要在.bashrc.bash_profile上运行的其他脚本

例如在.bashrc中:

export PATH="/custom/path:$PATH"

运行集成外壳程序(CTRL + `)时,一切正常,因为我看到$PATH包含/custom/path

但是当我尝试运行任务脚本(https://code.visualstudio.com/docs/editor/tasks#vscode

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "type": "eslint",
            "problemMatcher": [
                "$eslint-stylish"
            ]
        },
        {
            "label": "Run tests",
            "type": "shell",
            "command": "./scripts/test.sh",
            "presentation": {
                "reveal": "always",
                "panel": "new"
            }
        }        
    ]
}

test.sh中的内容

echo $PATH

当我尝试运行任务“运行测试”时,它没有显示/custom/path,或者实际上,~/.bashrc~/.bash_profile中的任何内容都不包括在内。

我什至在test.sh中尝试过类似的方法,但仍然无法加载我的.bashrc

source /home/user/.bashrc
echo $PATH

下面是我的VSCode用户设置:

{
    "terminal.external.windowsExec": "C:\\windows\\Sysnative\\bash.exe",
    "terminal.integrated.shell.windows": "C:\\windows\\Sysnative\\bash.exe",
    "terminal.integrated.shellArgs.windows": ["--login"],
    "eslint.provideLintTask": true
}

问题是:

如何设置VSCode或Windows使用我的.bashrc.bash_profile运行任务?

1 个答案:

答案 0 :(得分:0)

这是因为我的*ngIf="user"

中的以下几行
.bashrc

因此,在更新了我的VSCode设置后,如下所示:

# If not running interactively, don't do anything
case $- in    
    *i*) ;;      
      *) return;;
esac#

我的{ "terminal.external.windowsExec": "C:\\windows\\Sysnative\\bash.exe", "terminal.integrated.shell.windows": "C:\\windows\\Sysnative\\bash.exe", "terminal.integrated.shellArgs.windows": ["-i"], "eslint.provideLintTask": true } 中的其余命令将被执行