【问题标题】:Git .bash_profile Not Working With the Right-clickGit .bash_profile 不使用右键单击
【发布时间】:2015-04-29 02:53:51
【问题描述】:

每当我右键单击文件夹并单击 Git Bash 时,我的 .bash_profile 都无法正常工作。当我打开带有桌面图标的 Git Bash 时,它工作得非常好。这是我的 .bash_profile:

source ~/git-completion.bash

green="\[\033[0;32m\]"
blue="\[\033[0;34m\]"
purple="\[\033[0;35m\]"
reset="\[\033[0m\]"

source ~/git-prompt.sh

export GIT_PS1_SHOWDIRTYSTATE=1

export PS1="$green\u$green\$(__git_ps1)$blue \w $ $reset"

我尝试搜索,但到目前为止我没有看到一些答案,或者至少没有提示可以回答我的问题。

顺便说一句,我从名为“使用 Git 和 Github”的 udacity 课程中获得了这段代码。他们在那里有一个论坛,但我只注册了免费课程,所以我无法访问它

提前致谢!

【问题讨论】:

  • 通过右键单击文件夹打开 git bash 并输入逗号 cd。检查.bash_profile是否存在于你被带到的目录中。
  • @LahiruChandima 我尝试右键单击一个文件夹并打开 git bash,然后输入 cd,然后我输入 ls -a 。 .bash_profile 存在于该特定目录中。
  • 然后尝试将.bash_profile 重命名为.bashrc 并重新打开git bash
  • @LahiruChandima 谢谢!成功了!
  • @LahiruChandima 你能解释一下如果我将.bash_profile 更改为.bashrc 会发生什么吗?我只想知道.bashrc是什么(或者两者有什么区别)。

标签: git bash git-bash .bash-profile


【解决方案1】:

Bash 源 .bash_profile 如果它作为登录 shell 打开。当您通过右键单击文件夹打开 git bash 时,它不会作为登录 shell 打开,因此 bash 不会源 .bash_profile。放置设置的正确文件是 .bashrc,它由 bash 在交互式非登录 shell 中提供。

只需将.bash_profile 重命名为.bashrc

【讨论】:

    【解决方案2】:

    为避免 bash 脚本中出现冗余内容,您可以使用以下命令创建 .bashrc:

    if [ -f ~/.bash_profile ]; then
        . ~/.bash_profile
    fi
    

    【讨论】:

    • 这是倒退吗?我的理解是 .bashrc 是为非登录 shell 运行的,.bash_profile 是为登录 shell 运行的。也就是说,您将只想在顶级 shell 调用中运行的东西放入.bash_profile,并将您想要在 easch 嵌套 shell 中运行的东西放入 .bashrc。因此,您通过.bash_profile 将自定义目录附加到PATH once 每个登录会话,然后PATH 不会在每个级别的 Bash 调用中保持冗余增长(您调用的脚本,以及它们调用的脚本)。
    猜你喜欢
    • 2012-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-06
    • 2011-07-20
    • 1970-01-01
    • 2019-04-12
    • 1970-01-01
    相关资源
    最近更新 更多