如何在VS Code中每次打开新终端窗口时运行某个命令?

3

我希望在VSCode终端中运行source ~/.bashrc,这样我就可以加载自己的命令并在其中运行,目前我必须在命令行上手动执行。是否有办法在终端启动之前运行该命令?(操作系统:Mac)


1
这是哪个操作系统?Windows、Linux还是macOS?根据不同的操作系统,你可能需要将命令放在~/.bash_profile中... - nwinkler
@nwinkler也许我的问题不太清楚,但我想在终端启动时运行该文件。类似于source ~/.bashrc这样的东西。 - Peak Sornpaisarn
我有同样的问题。对于我的用例,我想要将某些环境变量加载到终端,但我不希望这些变量在 VS Code 之外的终端环境中全局设置(例如,将我的 AWS 凭据加载到环境变量并设置一个 DEV_MODE=1 的环境变量,该变量由某些脚本使用)。 - aaronsteers
1个回答

3

由于您使用的是 macOS,因此不会使用 ~/.bashrc 文件,而是使用 ~/.bash_profile。您可以执行以下操作之一:

  • Put your custom commands in ~/.bash_profile, or
  • Source your ~/.bashrc from your ~/.bash_profile:

    • Create a file ~/.bash_profile with the following content:

      source ~/.bashrc
      
    • Give the new file the same permissions as ~/.bashrc


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接