提示中的Git分支名称

use*_*733 9 git bash gnu-screen

我能够在shell提示符中显示git分支名称.但每当我使用屏幕时,我都会得到

bash: parse_git_branch: command not found
Run Code Online (Sandbox Code Playgroud)

和git分支没有显示.请帮我在屏幕会议中得到这个.

我在.bash_profile中有以下内容.

parse_git_branch() {
    git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/
}

export PS1="[\W\$(parse_git_branch)]$ "
Run Code Online (Sandbox Code Playgroud)

我没有 .git-completion.bash

系统规格:

  • 操作系统:OSX 10.8.4
  • 终端和iTerm2
  • 屏幕版本:4.00.03(FAU)2006年10月23日

小智 5

在屏幕上运行,当我有同样的问题,并能够通过移动的定义,以解决parse_git_branch()从功能.bash_profile.bashrc.


Sim*_*ano 5

当您打开终端时,.bash_profile会执行并因此PS1被定义.然后执行屏幕,屏幕读取PS1包含调用的环境变量parse_git_branch并尝试解析它.但是,由于屏幕未执行.bash_profile,parse_git_branch因此未在屏幕内定义该功能.

移动PS1to 的定义.bashrc因为屏幕和iTerm都执行它.


Nic*_*lin 2

'您在 sed 语句末尾缺少一个:

parse_git_branch() {
    git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
export PS1="[\W\$(parse_git_branch)]$ "
Run Code Online (Sandbox Code Playgroud)

否则,它似乎对我有用bash-3.2

  • 我解决了。一旦我进入屏幕,我就会使用“source ~/.bash_profile”。它会恢复所有设置。谢谢您的帮助。 (4认同)