【问题标题】:VSCode terminal windows - git-bash aliases getting ignoredVSCode 终端窗口 - git-bash 别名被忽略
【发布时间】:2018-10-23 21:12:40
【问题描述】:

我在c:\Users\user\.bash_profileC:\Program Files\Git\etc\profile.d\aliases.sh 中创建了别名,但是这两个配置都被配置为使用 git bash 的 VSCode 集成终端忽略了:

"terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe",

如果我自己打开 GitBash - 别名可以正常工作

如何强制集成终端尊重配置?

【问题讨论】:

    标签: visual-studio-code git-bash


    【解决方案1】:

    您可以尝试添加到设置中:

    // The command line arguments to use when on the Windows terminal.
    "terminal.integrated.shellArgs.windows": [
        "--login", "-i"
    ],
    

    -i - 强制 shell 以交互方式运行。

    --login - 让这个 shell 表现得好像它是被登录直接调用的。当 Bash 作为交互式登录 shell 或作为带有 --login 选项的非交互式 shell 调用时,它首先从文件 /etc/profile 中读取并执行命令(如果该文件存在)。读取该文件后,它会按顺序查找 ~/.bash_profile~/.bash_login~/.profile,然后从第一个存在且可读的命令中读取并执行命令。

    当作为一个名为 sh 的交互式 shell 调用时,Bash 会查找变量 ENV,如果已定义,则扩展其值,并使用扩展后的值作为要读取和执行的文件的名称。由于作为 sh 调用的 shell 不会尝试从任何其他启动文件读取和执行命令,因此 --rcfile 选项无效。 使用名称 sh 调用的非交互式 shell 不会尝试读取任何其他启动文件。

    Read more.


    您也可以使用.bashrc 文件代替.bash_profile

    【讨论】:

    • 这也适用于我。关于如何在 phpstorm 上执行此操作的任何想法?顺便问一下,这是做什么用的?
    • GabMic,for PhpStormBash options.
    【解决方案2】:

    使用“--login”和“-i”shell 参数的解决方案对我不起作用。起作用的是在我的设置文件中使用 bash “-rcfile” shell 参数,如下所示:

    "terminal.integrated.shellArgs.windows": [ "-rcfile", "c:\Users\\.bash_profile", ],

    ... 其中 是我的 Windows 用户 ID,别名命令位于名为“.bash_profile”的文件中,该文件位于 c:\Users\

    【讨论】:

      【解决方案3】:

      我只是切换到我的根用户目录c:\Users\user 然后运行source .bashrc。这在我的机器上成功了,希望对您有所帮助。

      【讨论】:

        【解决方案4】:
        1. 在 c:\Users\username 中创建 .bashrc
        2. 添加别名,例如alias gotossh="cd /c/users/username/.ssh"
        3. 在您的终端中,在 c:\Users\username 中运行 source .bashrc
        4. 通过运行alias 确认别名有效

        您可能在 users 文件夹中没有 .bashrc 文件,请注意这一点。 还要记住正确编写路径,并且不要在等号之间留下任何空格,例如 alias="somecommand"

        截至 2020 年,无需添加 shellArgs。

        【讨论】:

          猜你喜欢
          • 2020-10-22
          • 1970-01-01
          • 1970-01-01
          • 2015-08-20
          • 2012-07-12
          • 2021-04-16
          • 2021-10-13
          • 2013-07-20
          • 2020-09-10
          相关资源
          最近更新 更多